Write
a function which returns 1 if the given number is palindrome otherwise returns
0.
#include<stdio.h>
#include<conio.h>
int
pelindrome(int);
int main()
{
int n,p;
clrscr();
printf("Enter a number :
");
scanf("%d",&n);
p=pelindrome(n);
if(p==1)
printf("%d is
pelindrome",n);
else
printf("%d is not
pelindrome",n);
getch();
return 0;
}
int
pelindrome(int n)
{
char a[6],b[6];
itoa(n,a,10);
strcpy(b,a);
strrev(b);
if(strcmp(a,b)==0)
return 1;
else
return 0;
}
Output:
Enter a number
: 123
123 is not
pelindrome
Enter a
number : 151
151 is
pelindrome
No comments:
Post a Comment