3. Consider the following functions: int func1(int x) { int r, s; r = 2 * x; if
ID: 3658593 • Letter: 3
Question
3. Consider the following functions: int func1(int x) { int r, s; r = 2 * x; if (r > 10) { s = x / 2; } else { s = x / 3; } return s - 2; } int func2(int a, int b) { int r, s; s = 0; for(r = a; r < b; r++) { s++; } return s; } What is the output from the following program fragments? int a, b; a. a = 10; cout << func1(a) << endl; b. a = 5; b = 12; cout << func2(a, b) << endl; c. a = 8; b = func1(a); cout << a << " " << b << " " << func2(a, b) << endl;Explanation / Answer
please rate - thanks
int func1(int x)
{ int r, s; r = 2 * x;
if (r > 10)
{ s = x / 2;
}
else
{ s = x / 3; }
return s - 2;
}
int func2(int a, int b)
{ int r, s; s = 0;
for(r = a; r < b; r++)
{ s++; }
return s; }
What is the output from the following program fragments?
int a, b;
a. a = 10; cout << func1(a) << endl;
x=10
r=20:r>10 yes s=10/2=5
answer is 5
b. a = 5; b = 12; cout << func2(a, b) << endl;
in func2
a=5, b=12
s=0:
r=5 s=1;
r=6, s=2;
r=7, s=3;r=8, s=4;
r=9, s=5; r=10, s=6
r=11, s=7
r = 12
answer is 7
c. a = 8; b = func1(a); cout << a << " " << b << " " << func2(a, b) << endl;
in func1 x=8
r=16
16>10 s=4
in main b=4
call func2
a=8, b=4
s=0
r=8, never does loop 0 is returned
output is
8 4 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.