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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a function that will take in a phone number and output all possible alphabetical combinations

603


which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above

1419


Give basis knowledge of web designing ...

1574


Calculate 1*2*3*____*n using recursive function??

1517


What is the collection of communication lines and routers called?

614






Explain the difference between getch() and getche() in c?

565


How are strings stored in c?

595


What are pointers in C? Give an example where to illustrate their significance.

751


Differentiate between the expression “++a” and “a++”?

705


Describe the order of precedence with regards to operators in C.

633


Why is c called c?

629


When I tried to go into a security sites I am denied access and a message appeared saying 'applet not initialize'. How can I rectify this problem.

1531


What is the significance of scope resolution operator?

862


What is the difference between scanf and fscanf?

664


What is self-referential structure in c programming?

660