How will the program execute this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How will the program execute this code?

static int Fact(int num) { if (num == 1) { return 1; } return num * Fact(num - 1);} Like this: //(Num= 4) static int Fact(int 4) { if (num == 1) { return 1; } return 4 * Fact(4 - 1)=—> Return 4 * Fact(4-1)=3 * Fact(3-1)= 2 * Fact(2-1 if num ==1) = 1 Or will it behalve more like a loop: static int Fact(int 4* fact(3)*Fact(2) etc) { if (4 == 1) { return 1; } return 4 * Fact(num - 1);} Static int Fact( 4*3*2*1){} or Static int Fact(int 4){ 4*3*2*1}

29th Jan 2019, 6:45 PM
Mike Willems
Mike Willems - avatar
4 Answers
+ 2
Did you write this code in code playground and insert in this question
29th Jan 2019, 7:26 PM
AKS
AKS - avatar
0
where will the loop take place?
29th Jan 2019, 6:47 PM
Mike Willems
Mike Willems - avatar
0
yes sry
30th Jan 2019, 4:21 PM
Mike Willems
Mike Willems - avatar
0
if u have a method that calls itself wil it then go like a loop up down or wil it go one time down and write it out?
30th Jan 2019, 4:23 PM
Mike Willems
Mike Willems - avatar