【正文】
oat p, pp, r, v。n)。 f2 = f。 int i = 2, m。 int sum = 0。 printf ( Please input a number: )。} } 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。 printf ( About %.2fx*x + %.2fx + %.2f = 0: , a, b, c )。 scanf ( %f, amp。 } 6/2/2022 Chapter 5 Decision Making and Branching main ( ) /* (c) */ { float x。 } else printf ( y = 0\n )。 default: discount = 。 break。price )。 else printf ( Not admitted\n )。chem )。 printf ( Mathematics: )。 scanf ( %f, amp。c )。 printf ( a = )。 scanf ( %d, amp。 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。 printf ( %d*%d is\t\t%5d\n, y/10, x, y/10*x )。 } 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 ( (a) (x+y)/(xy) = %f\n, (x+y)/(xy) )。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。y )。 printf ( The number is: %.0f\n , x )。 printf ( %d*%d is\t\t%6d\n, y%10, x, y%10*x )。even39。 printf ( Please input an integer: )。 printf ( Please input the value of a, b, c, d, m and n:\n )。 scanf ( %f, amp。 printf ( n = )。 printf ( Please input scores of the 3 subject : )。 scanf ( %f, amp。 (math+phy+chem=200 || math+phy=150) ) printf ( Admitted!\n )。 scanf ( %f, amp。 case 2: discount = 。 break。 else printf ( y = 1\n )。 else printf ( y = 1\n )。 printf ( a = )。c )。 else printf (There are 2 real roots: %.2f, %.2f.\n, (b + sqrt(f))/2/a, (b sqrt(f))/2/a )。 long n = 1。 } 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。 } 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 print the first m Fibonacci numbers. (Hint: After the first two numbers in the series, each number is the sum of the two preceding numbers.) 6/2/2022 Chapter 6 Decision Making and Looping main ( ) { long f1 = 1, f2 = 1, f = 1。 f1 = f2。x, amp。 } 6/2/2022 Chapter 6 Decision Making and Looping Write a program to evaluate the following investment equation V = P(1+r)n and print the tables which would give the value of V for various bination of the following values of P, r and n. P: 1000, 2022, 3000, ……, 10,000 r: , , , ……, n: 1, 2, 3, ……, 8 (I change the value of n for format.) (Hint: P is the principal amount and V is the value of money at the end of n years. This equation can be recursively written as V=P(1+r) P=V That is, the value of money at the end of first year bees the principal amount for the next year and so on.) 6/2/2022 Chapter 6 Decision Making and Looping main ( ) { int n。 n++ ) if ( n == 1 ) printf ( %d year, n )。 n++ ) { v = pp * ( 1 + r )。 i = 5。 i ) { for ( j = 1。 for ( i = 1。 } 6/2/2022 Chapter 6 Decision Making and Looping Write a program to print a table of values of the function y = exp(x) for x varying from to in steps of . The table should appear as follows: Table for Y = EXP(X) ________________________________________________ x …… …… ________________________________________________ 6/2/2022 Chapter 6 Decision Making and Looping include main ( ) { double x = 0。 i = 9。 printf ( \t%.2le, exp(x) )。number )。 for ( j =1。 if ( i =4 amp。 j++ ) printf ( * )。 i++ ) n = n * i。 int n, i。 scanf ( %d, amp。 and the program should also count the number of spoilt ballots. 6/2/2022 Chapter 7 Arrays main ( ) { int count, candidate[6]={0}, spoilt = 0。 count = 5) candidate[count] ++。 printf ( Spoilt ballots: %d\n, spoilt )。 else p[i][j] = p[i1][j1] + p[i1][j]。 int i, j, k。 scanf(%f, amp。 scanf(%f, amp。 j ++ ) { for ( i = 0, max = s[0][j], k = 0。 k = i。 printf(Input %d numbers of array b in ascending order:\n, N)。amp。 for ( k = 0。 j N。 j++ ) scanf ( %d, amp。 k N。 j N。 printf ( \n )。 i N。 } for ( i = 0。a[i] )。 a[k] = a[Ni]。 i = 0。 if ( flag ) printf ( The number %d is on the position %d.\n, n, i+( ji )/2+1 )。\039。 } else { if(i==3) printf ( The correct answer is: %s\n, name)。 printf ( Which position do you want to extract the string from?)。 str[i] amp。 printf ( Which word do you want to count? )。 continue