//Write a program to check a number is palindrom or not #include<stdio.h> #include<conio.h> void main() { int n,a,r=0,temp; clrscr(); printf("Enter any number:\n"); scanf("%d"&n); temp = n;// copy number to temp while(n)//run loop until n have some value { a=n%10;//from this we get last digit r=r*10+a; n=n/10; } if(temp==r) printf("%d is Palindrom",temp); else printf("%d is not Palindrom",temp); getch(); } /*For example we input a number 121 then a = 121%10 = 1 r = 0*10 + 1 = 1 n = 121/10 = 12 a = 12%10 = 2 r = 1*10 + 2 = 12 n = 12/10 = 1 a = 1%10 = 1 r = 12*10 + 1 = 121 n = 1/10 = 0 temp is equal to r, so that 121 is Palindrom*/
Comments
Post a Comment