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
Write a function that will take in a phone number and output all possible alphabetical combinations
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
Give basis knowledge of web designing ...
Calculate 1*2*3*____*n using recursive function??
What is the collection of communication lines and routers called?
Explain the difference between getch() and getche() in c?
How are strings stored in c?
What are pointers in C? Give an example where to illustrate their significance.
Differentiate between the expression “++a” and “a++”?
Describe the order of precedence with regards to operators in C.
Why is c called c?
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.
What is the significance of scope resolution operator?
What is the difference between scanf and fscanf?
What is self-referential structure in c programming?