What will be the output of the following C code? [code]#include<stdio.h> main() { int n; n=f1(4); printf("%d",n); } f1(int

Lan Anh

New member
What will be the output of the following C code?
Code:
#include<stdio.h>
main()
{
    int n;
    n=f1(4);
    printf("%d",n);
}
f1(int x)
{
    int b;
    if(x==1)
        return 1;
    else
        b=x*f1(x-1);
        return b;
}
A. 24
B. 4
C. 12
D. 10
 
Answer: a
Explanation: The above code returns the factorial of a given number using the method of recursion. The given number is 4 in the above code, hence the factorial of 4, that is, 24 will be returned.
 

Tìm kiếm

Back
Top