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
Explain what are the different file extensions involved when programming in c?
What is the advantage of an array over individual variables?
hello freinds next week my interview in reliance,nybody has an idea about it intervew questions..so tell
Write a program to print "hello world" without using a semicolon?
Explain how do you convert strings to numbers in c?
Explain what header files do I need in order to define the standard library functions I use?
Explain how are 16- and 32-bit numbers stored?
Why are all header files not declared in every c program?
Define Spanning-Tree Protocol (STP)
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.
What is the difference between printf and scanf )?
What are the basic data types associated with c?
Why do we need arrays in c?
Explain the binary height balanced tree?
What language is lisp written in?