Program to fcheck whether a number is palindrome or not


Program to check whether a number is palindrome or not

#include <stdio.h>
#include <conio.h>

void main()
{
int result=0;
int n;
int rem=0;
int x=0;

clrscr();

printf("Enter number:");
scanf("%d",&n);

x=n;

while(n>=1) //the loop will execute until nuber is greater than 1
{
rem=n%10; //Here remainder is obtained
n=n/10; //number is divided by 10
result=result*10+rem; //result is obtained

}

if(x==result)
{
printf("Number is palindrome");
}
else
{
printf("Number is not paindrome");
}

getch();
}

Output :

0 comments:

Post a Comment