1. The following if statement is unnecessarily complicated. Simplify it as much as possible.
(Hint: The entire statement can be replaced by a single assignment.) if (age =13)
if (age <=19)
teenage = true
else
teenage = false
else if (age < 13)
teenage = false
2. Write a program that asks the user for a two-digit number, and then prints the English word for the number:
Enter a two-digit number: 45 you entered the number forty-five.
Hint: Break the number into two digits. Use one switch statement to print the word for the first digit (“twenty”, “thirty”, and so forth). Use a second switch statement to print the word for the second digit. Don’t forget that the numbers between 11 and 19 require special treatment.
3. What output does each of the following program fragment produce?
(a) i = 1; (b) i = 9384; (c) i = 5; while (i <= 128) { do { j = i - 1;
printf("%d ", i); printf("%d ", i); for (; i 0, j 0; --i, j = i-1) i *= 2; i /= 10; printf("%d ", i);
} } while (i 0);
4. What output does each of the following flowcharts produce? Write a program fragment in C for each
of the flowcharts, and submit the codes online. of the flowcharts, and submit the codes online.
5. The value of the mathematical constant can be expressed as an infinite series:
Write a program that approximate by computing the value of
where n is an integer entered by the user. Save and submit the program as a3 epsilon0.c.
6. The attached flowchart a3 epsilon.rap provides a modified solution to Q3.5. It allows for continuous addition of terms until the current term becomes less than a small (floating-point) number ε entered by the user. Write an equivalent program in C, and save and submit the program as a3 epsilon1.c.