Thursday 3 October 2013

Determining whether a given number is Palindrome or not using C

#include<stdio.h>
main()
{
int num,rem,rev=0,temp;
printf("\n(There is) none worthy of worship except Allah(Subhanahu wa ta'ala).Muhammad(Sallallahu alayhi wasallam) is Messenger of ALLAH(Subhanahu wa ta'ala).\n");
printf("Enter the number:\t");
scanf("%d",&num);
temp=num;
while(num>0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
if(temp==rev)
printf("Given number(%d) is a palindrome\n",temp);
else
printf("Given number(%d) is not a palindrome\n",temp);
}

No comments:

Post a Comment