//To check if a number is a palindrome or not //@author-Karan Narain(karan@iitk.ac.in) #include int main() { int n,d,i,rev=0,m; /*The while loop below is included to satisfy the requirement that the inputs need to be positive.The while loop keeps repeating till the user enters valid inputs.To enter into this while loop the first time,we initialize n to an illegal value(-1).We maintain a counter i which counts the number of times the user has entered values and display a message accordiingly*/ n=-1; i=0; while((n<=0)||(n>=10000)) { //This is the first time the user is entering the value if(i==0) printf("\nPlease enter a positive value for n\n"); //The user had entered an incorrect value.Print appropriate message else printf("The value of n needs to be positive and less than 10000.Please enter a proper value\n"); scanf("%d",&n); i++; } m=n; //Find out each digit individually and add it to the unit's place of rev while(m>0) { d=m%10; rev=rev*10+d; m=m/10; } if(rev==n) printf("The reverse of %d is %d and so it is a palindrome\n",n,rev); else printf("The reverse of %d is %d and so it is not a palindrome\n",n,rev); return 0; }