(C syntax, question 21) four-digit integer, four-digit syntax
Knowledge point:
For statement, if statement flexible use
Content: program to find the number of relationships in the four-digit integer abcd that meet the following requirements: (AB + cd) = abcd
Input description:
No input
Output description:
Output abcd, from small to large, one row.
1 #include <stdio.h> 2 int main() 3 { 4 int i,a,b; 5 for(i=1000;i<10000;i++) 6 { 7 a=i/100; 8 b=i%100; 9 if((a+b)*(a+b)==i)10 {11 printf("%d\n",i);12 }13 }14 return 0;15 }
C language: returns a four-digit integer in reverse order.
// If you only want to output data in reverse order, this will be fine # include <stdio. h> # include <string. h> int main () {char Num [20]; puts ("enter a number:"); gets (Num); puts (strrev (Num )); return 0 ;}
Enter a four-digit positive integer to show the sum of the numbers and the sum of the numbers (c)
The specific process is as follows:
# Include <stdio. h>
Int main (){
Int a, B, c, d, n, x;
Printf ("input a four-digit positive integer n :");
Scanf ("% d", & n );
X = n;
A = n % 10, n = n/10;/* obtain a single digit */
B = n % 10, n = n/10;/* obtain ten digits */
C = n % 10, n = n/10;/* obtain a hundred digits */
D = n % 10;/* obtain the number of thousands */
Printf ("% d \ n", a + B + c + d, x );
Return 0;
}
Hope to help you