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

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

2530


a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above

680


Are the outer parentheses in return statements really optional?

572


Give me the code of in-order recursive and non-recursive.

884


What is the main difference between calloc () and malloc ()?

570






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.

4496


How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?

592


Why do we use return in c?

568


What are conditional operators in C?

621


What is extern variable in c with example?

538


What is the use of bit field?

638


Explain how does free() know explain how much memory to release?

572


Give differences between - new and malloc() , delete and free() ?

607


what are # pragma staments?

1624


Explain enumerated types in c language?

602