Write a recursive program in ‘C’ to find whether a given five digit number is a palindrome or not. 10m Dec2005

By | June 12, 2014

Write a recursive program in ‘C’ to find whether a given five digit number is a palindrome or not. 10m Dec2005

#include<stdio.h>
int flag=0;
void palin(int,int*);
void main()
{
int a;
clrscr();
printf(“Enter the number “);
scanf(“%d”,&a);
palin(a,&a);
if(flag==0)
printf(“\nThe number is palindrome…”);
else
printf(“\nThe number is not palindrome…”);
getch();
}

void palin(int x,int* y)
{
int a,b;
if(x%10==0&&x/10==0)
return;
else
{
a=x%10;
palin(x/10,y);
b=*y%10;
*y=*y/10;
if(a!=b) flag=1;
}
}

#include<stdio.h>
int flag=0;
void palin(int,int*);
void main()
{
int a;
clrscr();
printf("Enter the number ");
scanf("%d",&a);
palin(a,&a);
if(flag==0)
printf("\nThe number is palindrome...");
else
printf("\nThe number is not palindrome...");
getch();
}
void palin(int x,int* y)
{
int a,b;
if(x%10==0&&x/10==0)
return;
else
{
a=x%10;
palin(x/10,y);
b=*y%10;
*y=*y/10;
if(a!=b) flag=1;
}
}

Screen Shots:-

C_program_Rec_Palindrome

C_program_Rec_Palindrome_Output

Leave a Reply