/* * Chapter 6 * Selftest.txt * John Stile */ 1. If a program includes the following code, which of the printf statements are executed? Why? yy=3; // execute assignment xx=(7*yy); // execute assignment if ( xx > 20) // 7*3=21, which is greater than 20, so ececute if block printf("A"); // exectue print, as inside if block printf("B); // execute print, note it is not in the if block else // error, there is no matching if block. If {} where used it would evaluate false. printf("C"); // not executed, part of else block. printf("D"); // execute print, not part of else block. 2. If a branching program includes four options, a) What is the maximum number of options that will be run in one program execution if the program is an else/if program? b) What is the maximum number of options that will be run in one program execution if the program is an if/else program? 3. In a switch/case branching program, why is the break needed? To exit the switch, and not run the rest of the code in the switch 4. Write a progrma named digitcounter.c that reads input determines the number od digits in the input output the result. To make the program count digits, redirect the output of who to the program. who |digitcounter 5. Write a program named evenorodd.c that reads an integer and determins and prints if the number is even or odd. Display an error message when a float is entered insted of an integer.