What is the output of the following program Show all your wo

What is the output of the following program? Show all your work for partial credit. #include int function1(int a, int b) {return (a + 2 * b);} int function2 (int a) {return (2* a + 1);} int main() {int i=2 int x; While (i5) x = function1 (i + 1, i + 1); else x = function2 (i+1)-1; printf (\"%d\ \", x); i = i + 1;} return(0);}

Solution

Output:

9
12
15
8
9
10
11
12

Explanation:

function1 will execute when the i value is lesss then 5 . if it is 5 or more than the function2 will execute.
for i values 2,3,4 ...function1 will execute.
for i=2, function1 will return 9 function(3,3)===>return(3+2*3)
for i=3, function1 will return 12 function(4,4)===>return(4+2*4)
for i=4, function1 will return 15 function(5,5)===>return(5+2*5)

for i values 5,6,7,8,9 ...function2 will execute.
for i=5, function2 will return 8 function(5,5)===>return(2*5+1)
for i=6, function2 will return 9 function(6,6)===>return(2*6+1)
for i=7, function2 will return 10 function(7,7)===>return(2*7+1)
for i=8, function2 will return 11 function(8,8)===>return(2*8+1)
for i=9, function2 will return 12 function(9,9)===>return(2*9+1)

 What is the output of the following program? Show all your work for partial credit. #include int function1(int a, int b) {return (a + 2 * b);} int function2 (i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site