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;
}
Answer: Option
Explanation:
Yes, this function calculates and return the factorial value of an given integer num.
Discussion:
19 comments Page 2 of 2.
Aman said:
1 decade ago
But there is no value for number?
Nikky said:
1 decade ago
What is the value of num?
Hari said:
1 decade ago
How it calculate the factorial values here please explain step by step?
Srikanth said:
1 decade ago
What is the value of num variable?
Parth said:
1 decade ago
How it calculates factorial values?
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 *\
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 *\
Usha said:
1 decade ago
How it calculates fraction value?
Sreedhar said:
1 decade ago
In for loop, what is the value of num
Dheeraj said:
1 decade ago
Why return is used here?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers