【正文】
if ( x 0 ) printf ( y = 1\n )。 } 6/2/2022 Chapter 5 Decision Making and Branching main ( ) /* (b) */ { float x。x )。 } printf ( The amount to be paid is %.2f\n, price*(1discount))。 break。 default: discount = 。 case 1: discount = 。 if ( category == 39。category )。 } 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。 chem=40 amp。 if ( math=60 amp。phy )。 scanf ( %f, amp。 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) )。n )。 scanf ( %f, amp。 printf ( d = )。b )。 scanf ( %f, amp。 printf ( About a set of two liner equations:\n )。n )。 if ( n % 2 == 0 ) printf ( %d IS EVEN\n, n )。 printf ( Please input an integer: )。odd39。 printf ( \t\t______\n)。 printf ( \n\t\t%6d\n\t\t*%5d\n, x, y )。 printf ( Please input 2 twodigit integers: )。 scanf ( %f, amp。 printf ( (b) (x+y)/2 = %f\n, (x+y)/2 )。 printf ( y = )。 printf ( Please input the value of x and y:\n )。 printf ( x = )。 scanf ( %f, amp。 printf ( (c) (x+y)(xy) = %f\n, (x+y)*(xy) )。x )。 scanf ( %d%d, amp。 printf ( \t\t______\n)。 printf ( Add them\t%6d\n, y*x)。 of 39。 scanf ( %d, amp。 } 6/2/2022 Chapter 5 Decision Making and Branching main ( ) /* (b) */ { int n。 if ( n % 2 ) printf ( %d IS ODD\n, n )。 printf ( \tax1+bx2=m\n\tcx1+dx2=n\n )。a )。 printf ( c = )。 scanf ( %f, amp。m )。 printf ( \n About the set of two liner equations:\n )。 } 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。math )。 printf ( Chemistry: )。amp。amp。 char category。 printf ( Price: )。m39。 break。 } else switch ( (int) (price1)/100 ) { case 0: discount = 。 case 2: discount = 。 } 6/2/2022 Chapter 5 Decision Making and Branching Write a program that will read the value of x and evaluate the following using (a) nested if statements (b) else if statements, and (c) conditional operator ? : ??????????010001xf o rxf o rxf o ry6/2/2022 Chapter 5 Decision Making and Branching main ( ) /* (a) */ { float x。 if ( x != 0 ) { if ( x 0 ) printf ( y = 1\n )。 printf ( Please input the value of x: )。 else if ( x == 0 ) printf ( y = 0\n )。 scanf ( %f, amp。 printf ( Please input the value of a, b and c in the quadratic equation:\n ax*x + bx + c = 0\n )。 printf ( b = )。 scanf ( %f, amp。amp。 if ( f 0 ) printf(There are no real roots!\n)。 scanf ( %ld, amp。 /* number is decreased by 10 times */ } } 6/2/2022 Chapter 6 Decision Making and Looping The factorial of an integer m is the product of consecutive integers from 1 to m. That is, factorial m = m! = m (m1) …… 1. Write a program that putes and prints a table of factorials for any given m. 6/2/2022 Chapter 6 Decision Making and Looping main ( ) { int m。m )。 } printf ( %ld\n, n )。 scanf ( %ld, amp。 /* number is decreased by 10 times */ } printf ( The sum of the digits is %d.\n, sum )。 scanf ( %d, amp。 f = f1 + f2。 i ++。 scanf ( %f %d, amp。 count = n。 x to power n = %f\n, x, n, y )。 for ( p = 1000。 n = 8。 r 。 n = 8。 } } printf ( \nPress enter key to continue... )。 for ( i = 1。 j++ ) printf ( %d, i )。 i = 1。 for ( j = 1。 } } 6/2/2022 Chapter 6 Decision Making and Looping Write a program to read the age of 100 persons and count the number of persons in the age group 50 to 60. Use for and continue statements. 6/2/2022 Chapter 6 Decision Making and Looping main ( ) { int age, count = 0, i。 scanf ( %d, amp。 } printf ( The number of persons in the age group 50 to 60 is %d.\n, count )。 for ( i = 1。 for ( i = 1。 i = 9。 j++ ) { x = i + *j。 i++ ) printf ( _ )。 scanf ( %ld, amp。 m ++。 i ) { n = number。 printf ( %ld, n % 2 )。 i++ ) { printf ( \n )。 else if ( i =10 amp。 j = 18。 int i, m = 1。 i = m。 printf ( +1/%d!, m )。 } e=1+1/1!+1/2!+1/3!+1/4!+1/5!+1/6!+1/7!+1/8!+1/9!= 6/2/2022 Chapter 6 Decision Making and Looping The present value (popularly known as book value) of an item is given by the relationship. P = c(1d)n where c = original cost d = rate of depreciation (per year) n = number of years P = present value after n years If P is considered the scrap value at the end of useful life of the item, write a program to pute the useful life in years given the original cost, depreciation rate, and the scrap value. The program should request the user to input the data interactively. 6/2/2022 Chapter 6 Decision Making and Looping main ( ) { float c, d, p。c )。 printf ( The number of years is: )。 i = n。spoilt ballot39。 to end the voting.\n )。amp。count )。 count ++ ) printf(Candidate%3d ballots: %d \n,count,candidate[count])。 for ( i = 0。 j++ ) if ( j == 0 || i == j ) p[i]