(C syntax, question 21) four-digit integer, four-digit syntax

Source: Internet
Author: User

(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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.