Home > Back-end >  palindrome
palindrome

Time:06-10

#include
#include
#include

Int main ()
{
Int a, b, c, d;
int i;
For (I=1000; i<10000; I++)
{
A=I/1000;//one thousand
B=(I % 1000)/100;//one hundred
C=(I % 100)/10;//10
D=I % 10;//bits
If (a==d& & B==c)
Printf (" % d \ t ", I);
}
return 0;
}

CodePudding user response:

What's the problem?

CodePudding user response:

Another kind of writing, for reference:

 # include & lt; stdio.h> 
Int main (void) {
int i, j;
int count=0;
For (I=1; i <10; + + I) {
For (j=0; J & lt; 10; + + j) {
Printf (" % d % d % d % d ", I, j, j, I);
Putchar (count & lt; 9? "' : '\ n');
Count=(count + 1) % 10;
}
}
return 0;
}

CodePudding user response:

 # include & lt; stdio.h> 
//# include & lt; math.h>

Int rt_revers (int num);
Int main ()
{

int i;

For (I=1000; i <10000; I++)
If (I==rt_revers (I))
Printf (" % d \ t ", I);

Putchar (10);
# if 0
Int a, b, c, d;
int i;
For (I=1000; i<10000; I++)
{
A=I/1000;//one thousand
B=(I % 1000)/100;//one hundred
C=(I % 100)/10;//10
D=I % 10;//bits
If (a==d& & B==c)
Printf (" % d \ t ", I);
}
# endif
return 0;
}

Int rt_revers (int num)
{
Int new_num=0;

While (num) {
New_num=new_num 10 * 10 + num %;
Num/=10;
}

Return new_num;
}


For any integer (note that the value of the int don't overflow)

 # include & lt; stdio.h> 
//# include & lt; math.h>

Int rt_revers (int num);
Int main ()
{

int i;

For (I=1000; i <10000; I++)
If (I==rt_revers (I))
Printf (" % d \ t ", I);

Putchar (10);

return 0;
}

Int rt_revers (int num)
{
Int new_num=0;

While (num) {
New_num=new_num 10 * 10 + num %;
Num/=10;
}

Return new_num;
}

Concise version ~

CodePudding user response:

refer to the second floor wowpH response:
another kind of writing, for reference:

 # include & lt; stdio.h> 
Int main (void) {
int i, j;
int count=0;
For (I=1; i <10; + + I) {
For (j=0; J & lt; 10; + + j) {
Printf (" % d % d % d % d ", I, j, j, I);
Putchar (count & lt; 9? "' : '\ n');
Count=(count + 1) % 10;
}
}
return 0;
}

count
excess\ n and "ternary excess
The inner loop of fixed output 10
The inner loop ends line directly

CodePudding user response:

reference 4 floor lin5161678 response:
count
excess\ n and "ternary excess
The inner loop of fixed output 10
The end of the inner loop line directly can

Do write many,
 # include & lt; stdio.h> 
Int main (void) {
int i, j;
For (I=1; i <10; + + I) {
For (j=0; J & lt; 10; + + j) {
Printf (" % d % d % d % d ", I, j, j, I);
}
printf("\n");
}
return 0;
}

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html