i need someone to explain this codes to me
long fact(int n);
int main()
{ for (int i=-1; i<20; i++)
cout << "fact(" << i << ") = " << fact(i) << endl;
}
long fact(int n)
{ if (n < 2) return 1;
long f=1;
for (int i=2; i <= n; i++)
f *= i;
return f;
}
Answers
Answered by
4
- At statement 1 , function declaration is done
- At statement 2 , main function is defined
- after main function, long fact(int) is defined.
- at main function, fact() is called , inside for loop
- Which show the value of what long fact() function return.
- here on long fact() function, factorial of a number is calculated.
if not understand, then again asked it..I'll make you understand.
HAPPY CODING.
Similar questions