e.g 12321
Program below reads in a five-digit integer and determines whether or not it's a palindrome.
/* title: palindromeTester author: aeriqusyairi date: dec27 2011 */ #include<stdio.h> #include<stdlib.h> int main(){ int number=0,preserve=0,counter=1,f1=0,l1=0,f2=0,l2=0; printf("Input 5 digit integer: "); scanf("%d", &number); preserve = number; while(counter <= 5){ switch(counter){ case 1: l1 = number % 10; number /= 10; break; case 2: l2 = number % 10; number /= 10; break; case 3: number /= 10; break; case 4: f2 = number % 10; number /= 10; break; case 5: f1 = number % 10; number /= 10; break; default: break; } counter++; } if(f1 == l1 && f2 == l2) printf("Integer %d is a palindrome.\n\n", preserve); else{ printf("Integer %d is not a palindrome.\n\n", preserve); } system("pause"); return 0; };-)
Read more..
No comments:
Post a Comment