Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following functions: int func1(int x) { int r, s; r = 2 * x; if (r

ID: 1796752 • Letter: C

Question

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

a. a = 10;
cout << func1(a) << endl;      3
b. a = 5; b = 12;
cout << func2(a, b) << endl;     7
c. a = 8;
b = func1(a);
cout << a << " " << b << " " << func2(a, b) << endl;    8 2 0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote