Computer Science, asked by agrawalshruti111, 5 months ago

int func(int a, int b)
{
if(b==0)
return 0;
if(b==1)
return a;
return a + func(a,b-1);
}
what will be the output of func(3,8)?​

Answers

Answered by Ijack
1

Answer:

(3,3-1)

(3,2)

or it should be constant also

(0,2)

Answered by mahinderjeetkaur878
0

Answer: - 24.

Detailed answer: -

The output of the func(3,8) will be 24 if we execute the given program.

When we will execute the given program by putting a = 3 and b = 8: -

int func(int a, int b)

{

if(b==0)

return 0;

if(b==1)

return a;

return a + func(a,b-1);

}

Then,

The output will be 24.

The in the int function we will input the value of a = 3 and the value of b = 8.

Then both the if loop will be executed, and at last the value of the a will be added with the answer of the value of a multiplied by the value of b minus 1.

I.e.,

a = 3, b = 8

The given function - return a + func(a,b-1); will be executed and it will give the output as 24.

return a + func(a,b-1)

= 3 + 3 (8 - 1)

= 3 + 3 (7)

= 3 + 21

= 24

Therefore,

The final answer will be 24.

  • Your answer will be change when we will change the input of the value of the int numbers.

To know more about the topic, visit the below links: -

https://brainly.in/question/9030223

https://brainly.in/question/50944812

#SPJ3

Similar questions