write a recursive program in'c'to find whether a given five
digit number is a palindrome or not

Answers were Sorted based on User's Feedback



write a recursive program in'c'to find whether a given five digit number is a palindrome..

Answer / swapnil chhajer

//////////////////////////////////////////////////
//////// PROGRAM TO CHECK PALINDROME //////////
///// Developed By : Swapnil Chhajer ////////
//////////////////////////////////////////////////



#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int palindrome(int n)
{
char temp[10];
itoa(n,temp,10);
int len=strlen(temp);
int ret;

if(len == 1)
{
return 1;
}
else if(len == 2)
{
return(temp[0] == temp[1]);
}
else
{
if(temp[0] == temp[len-1])
{
temp[len-1]='\0';
ret = palindrome(atoi(temp+1));
}
else
{
return 0;
}
}
return ret;
}


int main()
{
int n;
printf("Enter the number : ");
scanf("%d",&n);
if(palindrome(n) == 1)
printf("\n\n:: PALINDROME ::");
else
printf("\n\n:: NOT A PALINDROME ::");
getchar();
return 0;
}

Is This Answer Correct ?    5 Yes 1 No

write a recursive program in'c'to find whether a given five digit number is a palindrome..

Answer / nikhil kumar saraf

void main()
{
int no,n,r=0,sum,a,c;
clrscr();
printf("Enter the number:-");
scanf("%d",&no);
n=no;
c=0;
while(n!=0)
{
n=n/10;
c++;
}
if(c!=5)
{
printf("The given number is not a five digit no.");
break;
}
else
{
n=no;
while(n!=0)
{
a=n%10;
r=(r*10)+a;
n=n/10;
}
if(r==no)
printf("The given no. is a pallidrom no.");
else
printf("The given no. is not pallidrom no.");
}
getch();
}

Is This Answer Correct ?    6 Yes 2 No

Post New Answer

More C Interview Questions

#include<stdio.h> main() { int i=5; printf("%d",i*i-- - --i*i*i++ + ++i); } tell the answer with correct reason .specially reason is important nt answer ans by turbo c is -39

1 Answers   GameLoft,


what would be the output of the following prog? Justify your answer? main() { unsigned char ch; unsigned char i; ch = -255; printf("%d",ch); i = -1; printf("%d",i); }

1 Answers  


How can a number be converted to a string?

1 Answers  


What are different types of pointers?

0 Answers  


What is Dynamic Initialization.

3 Answers  






What are local and global variables?

3 Answers  


What is wrong with this initialization?

0 Answers  


write a c/c++ programthat connects to a MYSQL server and checks if the INNoDB plug in is installed on it.If so your program should print the total number of disk writes by MYSQL.

0 Answers   BirlaSoft,


Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.

0 Answers  


please send me the code for multiplying sparse matrix using c

0 Answers  


How the processor registers can be used in C ?

7 Answers   HP,


write a c program to calculate sum of digits till it reduces to a single digit using recursion

0 Answers   IBM,


Categories