Download Solution to Quiz 1 - Computer Programming and Engineering Application | CS 2073 and more Quizzes Computer Science in PDF only on Docsity! CS 2073 , Quiz 1 Last Name First Name and Initial Introduction to C 1. Complete the C program below so that it will use the formula to calculate the volume of a sphere of radius . (Be careful in translating this formula into C.) Then print the value with 5 digits to the right of the decimal point. #include <stdio.h> int main() { double r = 4.2; /* sorry for typo, putting V instead of r */ /* put answer below */ double pi = 3.14159265358979; /* don’t need this many digits */ double V; V = (4.0/3.0)*pi*r*r*r; /* note: (4/3) == 1 */ printf("V = %.5f\n", V); /* or %0.5f or %9.5f etc. */ } 2. What values will be printed by the following program? (Show your work.) #include <stdio.h> int main() { int a, b; /* remember: a and b are integers */ a = 2 + 3*4; printf("a = %d\n", a); b = 2*3 + 15%4 + 1/4; printf("b = %d\n", b); } a = 2 + 12 = 14 b = 6 + 3 + 0 = 9 (15%3 = remainder when 15 is divided by 3) (1/4 is integer division, so it is 0) 3. Consider the following C program: #include <stdio.h> int main() { int income, tax; scanf("%d", &income); tax = 500; if (income < 8000) tax = 1000; else if (income <= 10000) tax = 1500; else if (income <= 12000) tax = 2000; else tax = 2500; printf("Income: %d, tax: %d\n", income, tax); } a. What will this program print if we type “11000” for the input? Income: 11000, tax: 2000 b. One part of the program has no effect on the value printed, no matter what the value of income is. What is this part? tax = 500; c. Fill in values of tax for the given ranges at the right: income tax 8000 1000 8000 – 10000 1500 10001 – 12000 2000 12000 2500