The following C function computes the factorial of an integer: int fact (int n )
ID: 3616458 • Letter: T
Question
The following C function computes the factorial of an integer:int fact (int n )
{ if (n<=1) return 1;
else return n * fact (n-1) ;
}
Could you please rewrite this function into imperative style (i.eusing variables and eliminating recursion).
I would like to have the main method also so I could test.
thanks,
Adam
PS : I do rate life saver
Explanation / Answer
please rate - thanks #include #include int fact(int); int main() { int n; printf("Enter the number: negative to exit"); scanf("%d",&n); while(n>=0) { printf("n!=%d",fact(n)); printf(" Enter number:negative to exit "); scanf("%d",&n); } getch(); return 0; } int fact(int n) {int i,nf=1; for(i=2;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.