



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A midterm exam for a c programming course, consisting of multiple-choice questions and programming tasks. The questions cover topics such as variable naming, data types, arithmetic operations, symbolic constants, loops, and conditional statements.
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!
(a) [1 points] counter good variable name
(b) [1 points] 3141519 stylistically poor variable name
(c) [1 points] sigma2nd good variable name
(d) [1 points] voidableCost good variable name
(e) [1 points] 2ndInput other illegal variable name
(f) [1 points] GRAV CONSTANT good symbolic constant name
(g) [1 points] powerOf2 good variable name
(h) [1 points] UNION good symbolic constant name
(i) [1 points] floor good variable name
(j) [1 points] costIn$ other illegal variable name
(a) [4 points] toupper(‘b’ + 3) ⇒ toupper(‘e’) ⇒ Value is ‘E’ which is a char
(b) [4 points] 3 / ceil(3.0 + 0.1) ⇒ 3 / ceil(3.1) ⇒ 3 / 4 ⇒ Value is 0 which is an int
(c) [4 points] 7 + (^6) * sqrt(9) ⇒ 7 + 6 * 3.0 ⇒ 7 + 18.0 ⇒ Result is 25.0, a double
(d) [4 points] fabs(-3) / 2 ⇒ 3.0/2 ⇒ Value is 1.5 which is a double
(e) [4 points] !isupper(‘a’) || isalnum(toupper(‘.’))⇒ !”false” || isalnum(‘.’) ⇒ “true” || “false” ⇒ Result is “true” (non-zero), a “boolean”
(a) [15 points] Uses a loop to compute and print out the first 15 powers-of-two (e.g., 2^0 , 2^1 , 2^2 , · · ·, 2^14 )
for (power = 0; power < 15; power++) { printf(‘‘%.0lf\n’’, pow(2, power)); }
(b) [10 points] If the variable counter is greater than 5 and less than 10, assign the variable inRange the value 1. Otherwise, inRange should be set to 0.
if ((counter > 5) && (counter < 10)) { inRange = 1; } else { inRange = 0; }
(a) [10 points] for (i = 0, j = 1; i < j; i++) { switch(i) { case 2: printf(‘‘Two’’); case 1: printf(‘‘Two’’); case 0: printf(‘‘One’’); case 3: printf(‘‘Three\n’’); break; case 4: printf(‘‘Four’’); break; default: printf(‘‘Something else\n’’); break; } } line# i j Output 0 0 1 1 4 One 5 (on same line as above) Three 6 12 1 0
(b) [10 points] int i = -1, k = 20; do { printf(‘‘%d\n’’, k); i += 1; } while(i = 0); line# i k Output 0 -1 20 1 2 20 3 0 4 0