1. Attached is an implementation of Problem 2.19 (problem_2-19_broken.c). It does not produce the correct results. Make the appropriate changes (i.e., fixes) to the code so that it is correct and readable. Submit a file called problem_2-19_fixed.c
problem_2-19_broken.c
// Arithmetic, Largest and Smallest Value #include
#include
int main(void) { int x = 0, y = 0, z = 0; printf("Enter three different integers: "); scanf("%d %d %d", &x, &y, &x); int sum = x + y + z; int average = sum / 3; int product = sum * 3; int min = -10000000; int max = 10000000; if(x
min = x; max = y; } else min = y; max = x; if(min > z) { min = z; } printf("Sum is %d\n", sum); printf("Average is %d\n", average); printf("Product is %d\n", product); printf("Smallest is %d\n", min); printf("Largest is %d\n", max); return 0; }
|
24 points possible using the rubric at the bottom of the assignment
Note that the textbook specifies the use of the single-selection if statement. In our modules, we will add the "else" clause which is not covered in Section 2.6. You can use this construct, even though it is not covered in the book yet. We will cover it in class.
2 Complete Problem 2.20. The program shall accept positive integer values for the radius. Submit a file called problem_2-20.c
24 points possible using the rubric at the bottom of the assignment
3. Attached is an out-of-order implementation of Problem 2.30 (problem_2-30_scrambled.c).
a. Unscramble the code.
b. Comment your unscrambled code and rename variables as you feel appropriate to explain what is happening.
problem_2-30_scrambled.c
{{ } } #include
if((x <= 99999)="" &&="" (x="">= 0)) int x = 0; int remain = x; int p = 10000; int main(void) p = p / 10; p = p / 10; p = p / 10; p = p / 10; printf("Enter 5 digit number: "); printf("%d\n", remain); printf("%d ", remain / p); printf("%d ", remain / p); printf("%d ", remain / p); printf("%d ", remain / p); remain = remain % p; remain = remain % p; remain = remain % p; remain = remain % p; return 0; scanf("%d",&x);=>
|
Submit a file called problem_2-30_unscrambled.c containing the unscrambled and readable code from steps (a) and (b).24 points possible using the rubric at the bottom of the assignment
c. Modify the program so that it prints the digits in reverse (e.g., 42359 results in "9 5 3 2 4"). After the program prints the digits in reverse, it should add the two numbers (e.g., 42359 and 95324) and print the sum.
Submit a separate file called program_2-30_reverse.c containing unscrambled, readable code that has been modified as specified in step (c).24 points possible using the rubric at the bottom of the assignment