The first: Whether the inverse number is equal to the original number
#include <stdio.h>int main () {int i,key,sum;//i the number of the loop variable 1000~9999, the key holds the I value after the remainder, sum holds the flashback number for (i=1000;i<=9999;+ +i) {sum=0;//Each loop is assigned an initial value of 0 key=i;//each cycle will be the new I value to the key so that the following while the loop to find sum while (key!=0) {SUM=SUM*10+KEY%10;KEY=KEY/10;} if (sum==i) {printf ("%d\t", I);}} return 0; }
The second type: the traditional way to find the number on a Chichong and then compare the bit and thousands, 10 and hundreds
#include <stdio.h>int main () {int a,b,c,d,i;for (i=1000;i<10000;++i) {a=i/1000;//digit b=i%1000/100;//10-bit c=i%100 /10;//hundred d=i%10;//Thousand if (a==d&&b==c) printf ("%d\t", I);} return 0;}
The third method uses the remainder formula to save the numbers on each digit first in the array a, then compare a[0] and a[3],a[1] and a[2].
Similar to the above, because it must be a four-digit number, so it is a[0] to a[3], this topic can refer to the previous notes
C Programming: Determine the number of positive integers within 10000 which are palindrome numbers. Time is around November 17, 2014
But I don't know why I always say my program is wrong when I submit it in the Blue Bridge Cup. Later discovered is to package output format for output a number on the line, no words, the topic did not say, sincerely hope that the Blue Bridge Cup, the better!
There is also a method that is not commonly used to remember here:
#include <stdio.h> #include <string.h>int main () {int I,j;int sum = 0;char buff[7] = ""; int len;for (i = 1000; I < 10000; i++) {sprintf (buff, "%d", i); len = strlen (buff); for (j = 0; J < Len/2; J + +) if (buff[j]! = buff[len-j-1]) break;if (j = = L EN/2) printf ("%s\n", Buff);} return 0;}
Finding a palindrome number of 4 digits