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
what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
Are the outer parentheses in return statements really optional?
Give me the code of in-order recursive and non-recursive.
What is the main difference between calloc () and malloc ()?
if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
Why do we use return in c?
What are conditional operators in C?
What is extern variable in c with example?
What is the use of bit field?
Explain how does free() know explain how much memory to release?
Give differences between - new and malloc() , delete and free() ?
what are # pragma staments?
Explain enumerated types in c language?