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 program to find out prime number using sieve case?
Stimulate calculator using Switch-case-default statement for two numbers
Why c is called procedure oriented language?
What is the purpose of realloc()?
What do you mean by command line argument?
Why can’t we compare structures?
What is the difference between struct and union in C?
Why c is known as a mother language?
Can we change the value of constant variable in c?
What is array of structure in c?
What is gets() function?
What is an array in c?
Write the syntax and purpose of a switch statement in C.
What are the types of unary operators?
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?