【正文】
f ( %18s, **** )。amp。 for ( i = 1。 j i。 for ( i = m。 n = number。 int m = 0, i, j。 } } for ( i = 1。 for ( j = 0。 i++ ) printf ( \t0.%d, i)。 i++ ) printf ( _ )。 int i, j。 if ( age 50 || age 60 ) continue。 i = 100。 j++ ) printf ( * )。 j = 5 i。 } } 6/2/2022 Chapter 6 Decision Making and Looping main ( ) /* (b) */ { int i, j。 i++ ) { for ( j = 1。ch )。 pp = v。 printf ( \n%.2f: , r)。 else printf ( %d years, n )。 p = p + 1000 ) { printf ( \nPrincipal amount: %.0f\nrate , p )。 float p, pp, r, v。 printf ( \nx = %f。n)。 float x, y。 f2 = f。 printf ( %12ld , f )。 int i = 2, m。 while ( n != 0 ) { sum = sum + n % 10 。 int sum = 0。 while ( m = 1 ) { n *= m。 printf ( Please input a number: )。 while ( n != 0 ) { printf ( %d, n % 10 )。} } 6/2/2022 Chapter 6 Decision Making and Looping Given a number, write a program using while loop to reverse the digits of the number. For example, the number 12345 should be written as 54321. (Hint: Use modulus operator to extract the last digit and the integer division by 10 to get the n1 digit number from the n digit number.) 6/2/2022 Chapter 6 Decision Making and Looping main ( ) { long n。 else if ( a == 0 ) printf(There is only one root: %.2f.\n, c/b)。 printf ( About %.2fx*x + %.2fx + %.2f = 0: , a, b, c )。b )。 scanf ( %f, amp。 printf ( y = %d\n, x 0 ? 1 : x 0 ? 1 : 0 )。 } 6/2/2022 Chapter 5 Decision Making and Branching main ( ) /* (c) */ { float x。x )。 } else printf ( y = 0\n )。 scanf ( %f, amp。 default: discount = 。 case 1: discount = 。 break。 break。price )。scanf ( %c, amp。 else printf ( Not admitted\n )。amp。chem )。 scanf ( %f, amp。 printf ( Mathematics: )。 if ( a*d c*b == 0) printf ( Error: the denominator is zero!\n )。 scanf ( %f, amp。 printf ( m = )。c )。 scanf ( %f, amp。 printf ( a = )。 } 6/2/2022 Chapter 5 Decision Making and Branching A set of two liner equations with two unknown x1 and x2 is given below: ax1 + bx2 = m cx1 + dx2 = n The set has a unique solution provided the denominator adcb is not equal to zero. Write a program that will read the values of constants a, b, c, d, m and n and pute the values of x1 and x2. An appropriate message should be printed if adcb=0. cbadmaxcbadbnmdx??????216/2/2022 Chapter 5 Decision Making and Branching main ( ) { float a, b, c, d, m, n。 scanf ( %d, amp。 if ( n % 2 ) printf ( %d IS ODD\n, n )。 and print the message NUMBER IS EVEN or NUMBER IS ODD (a) without using else option, and (b) with else option. 6/2/2022 Chapter 5 Decision Making and Branching main ( ) /* (a) */ { int n。 } 6/2/2022 Chapter 5 Decision Making and Branching Write a program to determine whether a given number is 39。 printf ( %d*%d is\t\t%5d\n, y/10, x, y/10*x )。y )。 } 6/2/2022 Chapter 4 Managing Input and Output Operations Write an interactive program to demonstrate the process of multiplication. The program should ask the user to enter two twodigit integers and print the product of integers as shown below. 45 37 7 45 is 315 3 45 is 135 Add them 1665 6/2/2022 Chapter 4 Managing Input and Output Operations main ( ) { int x, y, m, n。 printf ( Please input the number: )。 printf ( (a) (x+y)/(xy) = %f\n, (x+y)/(xy) )。x )。6/2/2022 Programming Exercises North China Electric Power University 6/2/2022 Chapter 4 Managing Input and Output Operations Write a program to read the values of x and y and print the results of the following expressions in one line: (a) (b) (c) yxyx??2yx?))(( yxyx ??6/2/2022 Chapter 4 Managing Input and Output Operations main ( ) { float x, y。 scanf ( %f, amp。y )。 } 6/2/2022 Chapter 4 Managing Input and Output Operations Write a program to read the following numbers, round them off to the nearest integers and print out the results in integer form: 6/2/2022 Chapter 4 Managing Input and Output Operations main ( ) { float x。 printf ( The number is: %.0f\n , x )。x, amp。 printf ( %d*%d is\t\t%6d\n, y%10, x, y%10*x )。 printf ( \t\t______\n)。even39。n )。 printf ( Please input an integer: )。 else printf ( %d IS EVEN\n, n )。 printf ( Please input the value of a, b, c, d, m and n:\n )。 printf ( b = )。 scanf ( %f, amp。d )。 printf ( n = )。 printf(\t%.2fx1+%.2fx2=%.2f\n\t%.2fx1+%.2fx2=%.2f\n,a,b,m,c, d,n)。 printf ( Please input scores of the 3 subject : )。 printf ( Physics: )。 scanf ( %f, amp。 phy=50 amp。 (math+phy+chem=200 || math+phy=150) ) printf ( Admitted!\n )。 printf ( Category (m/h): )。 scanf ( %f, amp。 ) switch ( (int) (price1)/100 ) { case 0: discount = 0。 case 2: discount = 。 break。 break。 printf ( Please input the value of x: )。 else printf ( y = 1\n )。 scanf ( %f, amp。 else printf ( y = 1\n )。x )。 printf ( a = )。 scanf ( %f, amp。c )。 b == 0 ) printf(There is no solution!\n)。 else printf (There are 2 real roots: %.2f, %.2f.\n, (b + sqrt(f))/2/a, (b sqrt(f))/2/a )。n )。 long n = 1。 printf ( %d!=, m )。 } 6/2/2022 Chapter 6 Decision Making and Looping Write a program to pute the sum of the digits of a given integer number. 6/2/2022 Chapter 6 Decision Making and Looping main ( ) { long n。n )。 } 6/2/2022 Chapter 6 Decision Making and Looping The numbers in the sequence 1 1 2 3 5 8 13 21 …… are called Fibonacci numbers. Write a program using a do...while loop to calculate and prin