C Program to write a function which returns 1 if the given number is palindrome otherwise returns 0
/* C Program to write a function which returns 1 if the given number is
palindrome otherwise returns 0. */
#include"stdio.h"
int
palindrome(int num);
void
main()
{
int
num, result;
printf("Enter
a number: ");
scanf("%d",
&num);
result
= palindrome(num);
if(result
> 0)
{
printf("\nThe
given number is palindrome.\n");
}
else
{
printf("\nThe
given number is not palindrome.\n");
}
}
int
palindrome(int num)
{
int
d=0, a, c = num;
while(num
!= 0)
{
a
= num % 10;
d
= d*10 + a;
num
= num / 10;
}
printf("%d
",d);
if(c
== d)
{
return
1;
}
else
{
return
0;
}
}
Output:
Comments
Post a Comment