Please refer to the following code when answering questions 1 through 3: #includ
ID: 3696263 • Letter: P
Question
Please refer to the following code when answering questions 1 through 3:
#include <stdio.h>
int main() {
int a = 5, b = 7, c = 2;
a = 2*b + c;
printf("a = %d, b = %d, c = %d ", a, b, c);
b = 2*c + a;
printf("a = %d, b = %d, c = %d ", a, b, c);
c = 2*a + b;
printf("a = %d, b = %d, c = %d ", a, b, c);
return 0;
}
1) What is the first line of output of the program above?
a) a = 5, b = 7, c = 2 b) a = 16, b = 7, c = 2
c) a = 9, b = 7, c = 2 d) a = 12, b = 7, c = 2
2) What is the second line of output of the program above?
a) a = 16, b = 9, c = 2 b) a = 9, b = 9, c = 2
c) a = 16, b = 20, c = 2 d) a = 16, b = 9, c = 7
3) What is the third line of output of the program above?
a) a = 16, b = 9, c = 17 b) a = 16, b = 9, c = 41
c) a = 16, b = 20, c = 49 d) a = 16, b = 20, c = 56
4) What is the output produced by the code segment below?
int a = 3, b = 7;
if (2*a > b || b < 3*a)
printf("A");
if (2*a > b && b < 10*a)
printf("B");
else
printf("C");
a) A b) B c) AB d) AC
5) What is the output produced by the code segment below?
int a = 4, b = 6;
if (a > b)
if (!b)
printf("A");
else
printf("B");
printf("C");
a) A b) B c) AC d) BC
6) What is the output produced by the code segment below?
int grade = 88;
if (grade >= 60) printf("D");
if (grade >= 70) printf("C");
if (grade >= 80) printf("B");
if (grade >= 90)
printf("A");
else
printf("F");
a) DCBF b) DCB c) B d) D
7) What is the output produced by the code segment below?
int i, sum;
sum = 0;
for (i=3; i<10; i+=3)
sum += i;
printf("i = %d, sum = %d ”, i, sum);
a) i = 9, sum = 9 b) i = 9, sum = 18
c) i = 12, sum = 18 d) i = 12, sum = 30
8) What is the output produced by the code segment below?
int i, sum;
sum = 0;
for (i=3; i<10; i+=3); // Last semicolon is intentional.
sum += i;
printf("i = %d, sum = %d ”, i, sum);
a) i = 9, sum = 9 b) i = 12, sum = 12
c) i = 12, sum = 18 d) i = 12, sum = 30
Explanation / Answer
Question 1:
#include <stdio.h>
int main() {
int a = 5, b = 7, c = 2;
a = 2*b + c;
printf("a = %d, b = %d, c = %d ", a, b, c);
b = 2*c + a;
printf("a = %d, b = %d, c = %d ", a, b, c);
c = 2*a + b;
printf("a = %d, b = %d, c = %d ", a, b, c);
return 0;
}
Answer: 1) B 2) C 3) D (d) a = 16, b = 20, c = 52) Note: C= 52 here not 56, option wrong,
Question 2:
int a = 3, b = 7;
if (2*a > b || b < 3*a)
printf("A");
if (2*a > b && b < 10*a)
printf("B");
else
printf("C");
Answer: C --- AC
Question 3:
int a = 4, b = 6;
if (a > b)
if (!b)
printf("A");
else
printf("B");
printf("C");
Answer: it should print value C but i dont see this option in your option.
Question 4:
int grade = 88;
if (grade >= 60) printf("D");
if (grade >= 70) printf("C");
if (grade >= 80) printf("B");
if (grade >= 90)
printf("A");
else
printf("F");
Answer: A --- DCBF
Question 5:
int i, sum;
sum = 0;
for (i=3; i<10; i+=3)
sum += i;
printf("i = %d, sum = %d ”, i, sum);
Answer: c) i = 12, sum = 18
Question 6:
int i, sum;
sum = 0;
for (i=3; i<10; i+=3); // Last semicolon is intentional.
sum += i;
printf("i = %d, sum = %d ”, i, sum);
Output: b) i = 12, sum = 12
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.