/* Write a complete C program that checks if a number entered by the user is a palindrome. A palindrome is defined as a number that can be written in the same way left-to-right and right-to-left. For example, 121, 3553, 531135, 2795972, are all palindromes, but 453,1232, 123123 are not palindromes. The user must enter the number on one input line as a single integer, i.e., it is not OK to ask the user to enter the individual digits separately. You can assume that the user will always enter a positive integer number that fits within the size limits of the int data type. */ #include #include int main() { int i, n, digits; printf("Enter an integer number: ", n); scanf("%d", &n); int a[15]; // put the individual digits of the number in an array digits=0; do { a[digits]=n%10; n/=10; digits++; }while(n>0); // print the entries of the array (for debugging only) for(i=0; i < digits; i++) printf("%d, ", a[i]); // check if the number is a palindrome int palindrome=1; // assume that it is indeed a palindrome for(i=0; i< digits/2; i++) { if(a[i] != a[digits-1-i]) { palindrome=0; break; // we can stop here } } if(palindrome == 1) printf("\n\nThe number is a palindrome.\n"); else printf("\n\nThe number is NOT a palindrome.\n"); printf("\n"); system("pause"); }