C Programming - Functions - Discussion

Discussion Forum : Functions - Point Out Correct Statements (Q.No. 3)
3.
Which of the following statements are correct about the function?
long fun(int num)
{
    int i;
    long f=1;
    for(i=1; i<=num; i++)
        f = f * i;
    return f;
}
The function calculates the value of 1 raised to power num.
The function calculates the square root of an integer
The function calculates the factorial value of an integer
None of above
Answer: Option
Explanation:

Yes, this function calculates and return the factorial value of an given integer num.

Discussion:
19 comments Page 1 of 2.

Dheeraj said:   1 decade ago
Why return is used here?

Sreedhar said:   1 decade ago
In for loop, what is the value of num

Usha said:   1 decade ago
How it calculates fraction value?

Rohit said:   1 decade ago
@usha

If num =3 \* 3! = 6 *|
i=1 , f=1
Executes the for loop now i=1, 1<=3,post increment so i= 2 for next time

f= f*i =1*1 =1 --------returns f as 1
Next time after for loop
1*2 = 3-------------returns f as 2
After for loop
2*3 = 6 ---------------returns f as 6
Now for loops get failed in condition
So f=====6 \* ans *\

Parth said:   1 decade ago
How it calculates factorial values?

Srikanth said:   1 decade ago
What is the value of num variable?

Hari said:   1 decade ago
How it calculate the factorial values here please explain step by step?

Nikky said:   1 decade ago
What is the value of num?

Aman said:   1 decade ago
But there is no value for number?

Bharu said:   1 decade ago
Can anyone please explain this?


Post your comments here:

Your comments will be displayed after verification.