87 views

What is the output of the following program?

int fun (int z)
{
if( z==0 || z==1 )
return 1;
else
return fun(z-1) ;
}
int main()
{
int y;
y=fun(8);
printf(“%d”, y) ;
}

1. $1$
2. $36$
3. $8$
4. $40$

ans A

every time the fun(z) is just either calling fun(z-1) or returning 1 hence the output doesn’t depend on the value of z it will always return 1 , for every non negative z

1
199 views