【正文】
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。 printf ( Please input the value of x and y:\n )。 printf ( x = )。 scanf ( %f, amp。x )。 printf ( y = )。 scanf ( %f, amp。y )。 printf ( (a) (x+y)/(xy) = %f\n, (x+y)/(xy) )。 printf ( (b) (x+y)/2 = %f\n, (x+y)/2 )。 printf ( (c) (x+y)(xy) = %f\n, (x+y)*(xy) )。 } 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 ( Please input the number: )。 scanf ( %f, amp。x )。 printf ( The number is: %.0f\n , 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 ( Please input 2 twodigit integers: )。 scanf ( %d%d, amp。x, amp。y )。 printf ( \n\t\t%6d\n\t\t*%5d\n, x, y )。 printf ( \t\t______\n)。 printf ( %d*%d is\t\t%6d\n, y%10, x, y%10*x )。 printf ( %d*%d is\t\t%5d\n, y/10, x, y/10*x )。 printf ( \t\t______\n)。 printf ( Add them\t%6d\n, y*x)。 printf ( \t\t______\n)。 } 6/2/2022 Chapter 5 Decision Making and Branching Write a program to determine whether a given number is 39。odd39。 of 39。even39。 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 ( Please input an integer: )。 scanf ( %d, amp。n )。 if ( n % 2 ) printf ( %d IS ODD\n, n )。 if ( n % 2 == 0 ) printf ( %d IS EVEN\n, n )。 } 6/2/2022 Chapter 5 Decision Making and Branching main ( ) /* (b) */ { int n。 printf ( Please input an integer: )。 scanf ( %d, amp。n )。 if ( n % 2 ) printf ( %d IS ODD\n, n )。 else printf ( %d IS EVEN\n, n )。 } 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。 printf ( About a set of two liner equations:\n )。 printf ( \tax1+bx2=m\n\tcx1+dx2=n\n )。 printf ( Please input the value of a, b, c, d, m and n:\n )。 printf ( a = )。 scanf ( %f, amp。a )。 printf ( b = )。 scanf ( %f, amp。b )。 printf ( c = )。 scanf ( %f, amp。c )。 printf ( d = )。 scanf ( %f, amp。d )。 printf ( m = )。 scanf ( %f, amp。m )。 printf ( n = )。 scanf ( %f, amp。n )。 printf ( \n About the set of two liner equations:\n )。 printf(\t%.2fx1+%.2fx2=%.2f\n\t%.2fx1+%.2fx2=%.2f\n,a,b,m,c, d,n)。 if ( a*d c*b == 0) printf ( Error: the denominator is zero!\n )。 else printf (The result: x1 = %.2f, x2 = %.2f\n, (m*d b*n)/(a*d c*b), (n*a m*c)/(a*d c*b) )。 } 6/2/2022 Chapter 5 Decision Making and Branching Admission to a professional course is subject to the following conditions: (a) Marks in Mathematics = 60 (b) Marks in Physics = 50 (c) Marks in Chemistry = 40 (d) Total in all three subjects = 200 or Total in Mathematics and Physics = 150 Given the marks in the three subjects, write a program to process the applications to list the eligible candidates. 6/2/2022 Chapter 5 Decision Making and Branching main ( ) { float math, phy, chem。 printf ( Please input scores of the 3 subject : )。 printf ( Mathematics: )。 scanf ( %f, amp。math )。 printf ( Physics: )。 scanf ( %f, amp。phy )。 printf ( Chemistry: )。 scanf ( %f, amp。chem )。 if ( math=60 amp。amp。 phy=50 amp。amp。 chem=40 amp。amp。 (math+phy+chem=200 || math+phy=150) ) printf ( Admitted!\n )。 else printf ( Not admitted\n )。 } 6/2/2022 Chapter 5 Decision Making and Branching A cloth showroom has announced the following seasonal discounts on purchase of items: Write a program using switch and if statements to pute the amount to be paid by a customer. Purchase amount Discount Mill cloth Handloom items 0~100 5% 101~200 5% % 201~300 % % Above 300 % % 6/2/2022 Chapter 5 Decision Making and Branching main ( ) { float price, discount。 char category。 printf ( Category (m/h): )。scanf ( %c, amp。category )。 printf ( Price: )。 scanf ( %f, amp。price )。 if ( category == 39。m39。 ) switch ( (int) (price1)/100 ) { case 0: discount = 0。 break。 case 1: discount = 。 break。 case 2: discount = 。 break。 default: discount = 。 } else switch ( (int) (price1)/100 ) { case 0: discount = 。 break。 case 1: discount = 。 break。 case 2: discount = 。 break。 default: discount = 。 } printf ( The amo