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

Answers were Sorted based on User's Feedback



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

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

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

Answer / nikhil kumar saraf

void main()
{
int no,n,r=0,sum,a,c;
clrscr();
printf("Enter the number:-");
scanf("%d",&no);
n=no;
c=0;
while(n!=0)
{
n=n/10;
c++;
}
if(c!=5)
{
printf("The given number is not a five digit no.");
break;
}
else
{
n=no;
while(n!=0)
{
a=n%10;
r=(r*10)+a;
n=n/10;
}
if(r==no)
printf("The given no. is a pallidrom no.");
else
printf("The given no. is not pallidrom no.");
}
getch();
}

Is This Answer Correct ?    6 Yes 2 No

Post New Answer

More C Interview Questions

What is nested structure with example?

0 Answers  


main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }

2 Answers  


What are volatile variables in c?

0 Answers  


Explain the difference between strcpy() and memcpy() function?

0 Answers  


1 232 34543 4567654 can anyone tell me how to slove this c question

6 Answers  






Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors

3 Answers  


What is meaning of "Void main" in C Language.

24 Answers   Ford, GU, HCL, IBIBS, JUW, TCS,


What is hashing in c language?

0 Answers  


I didn't count the ducks that I saw in line, but I do remember that one duck was in front of two ducks, another duck behind two ducks. How many ducks did I see?

2 Answers  


What’s a signal? Explain what do I use signals for?

0 Answers  


progrem to generate the following series 1 12 123 1234 12345

6 Answers   HCL, Wipro,


HOW TO FIND OUT THE RREVERS OF A GIVEN DIGIT NUMBER IF IT IS INPUT THROUGH THE KEYBORD BY USING C LANGUAGE

3 Answers   Wipro,


Categories