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

Explain what are the different file extensions involved when programming in c?

836


What is the advantage of an array over individual variables?

965


hello freinds next week my interview in reliance,nybody has an idea about it intervew questions..so tell

1935


Write a program to print "hello world" without using a semicolon?

818


Explain how do you convert strings to numbers in c?

810


Explain what header files do I need in order to define the standard library functions I use?

850


Explain how are 16- and 32-bit numbers stored?

1009


Why are all header files not declared in every c program?

803


Define Spanning-Tree Protocol (STP)

863


One of the Institutes contains 5 student groups. Every group contains 4 students. Institute wants to store student group’s details in array. Group should contain group member’s details (name and registration number and age), project name, and mark of the group.

2402


What is the difference between printf and scanf )?

784


What are the basic data types associated with c?

1024


Why do we need arrays in c?

809


Explain the binary height balanced tree?

896


What language is lisp written in?

831