Returns the number of four digits.
First: whether the reverse order number is equal to the original number
# Include
Int main () {int I, key, sum; // I cyclic variable 1000 ~ 9999 of the number, the key stores the I value and returns the remainder. sum stores the inverted number for (I = 1000; I <= 9999; ++ I) {sum = 0; // The initial value of each loop is 0 key = I; // The New I value must be given to the key for each loop so that the following while LOOP calculates sum while (key! = 0) {sum = sum * 10 + key % 10; key = key/10;} if (sum = I) {printf ("% d \ t ", i) ;}} return 0 ;}
The second method: the traditional method is to find a number of 10 hundred thousand and then compare one digit and one thousand digits, ten digits and one hundred digits.
# Include
Int main () {int a, B, c, d, I; for (I = 1000; I <10000; ++ I) {a = I/1000; // single digit B = I % 1000/100; // ten digits c = I % 100/10; // hundreds of digits d = I % 10; // if (a = d & B = c) printf ("% d \ t", I) ;}return 0 ;}
The third method uses the remainder formula to first store the numbers on each table in array a, and then compares a [0] And a [3], a [1] and a [2].
It is similar to the above, because it must be a four-digit number, so it is from a [0] to a [3]. For this question, see previous notes.
C Programming: To determine which positive integers within 10000 are input numbers. The time is around November 17, 2014.
#include
int main(){int i,j,key,temp;int a[100];for(i=1000;i<=9999;++i){key=i;j=0;while(key!=0){temp=key%10;a[j]=temp;j++;key=key/10;}if(a[0]==a[3]&&a[1]==a[2]){printf("%d\t",i);}}return 0; }
But I don't know why I always say that my program is wrong when I submit it in the blue bridge cup. Later, I found that I had to change the package output format and output a number to get a line break. I was speechless and didn't talk about the question. I really hope the Blue Bridge cup will get better and better!
Another method is not frequently used here:
#include
#include
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 == len / 2 )printf("%s\n",buff);}return 0;}