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

Wt are the Buses in C Language

0 Answers   Infosys,


What is a Deque?

2 Answers  


What does the message "warning: macro replacement within a string literal" mean?

1 Answers  


Explain c preprocessor?

0 Answers  


What is an object?

5 Answers  


why TCS selected more student in the software field from all institution.

5 Answers   TCS,


Why c is a mother language?

0 Answers  


What is the 'named constructor idiom'?

0 Answers  


what is the difference b/w compiler and debugger?

2 Answers   Assurgent,


Write a program with dynamically allocation of variable.

0 Answers   Atos Origin,


What is the difference between struct and typedef struct in c?

0 Answers  


The postoder traversal is 7,14,3,55,22,5,17 Then ur Inorder traversal is??? please help me on this

1 Answers  


Categories