Question
Write a C program that uses a for loop to compute n factorial (n is a positive integer). Test your program using various n. Write
Write a C program that uses a for loop to compute n factorial (n is a positive integer). Test your program using various n. Write a main function to call the following recursive function we studied in class.
int factorial( int num )
{
if ( num == 0 || num == 1 )
return 1;
return num * factorial( num 1 );
}
Rewrite the recursive function above to track the execution of a recursive function. Use it to compute 6! and observe the execution process.
int factorial( int num )
{
int tmp;
printf(num = %d when entering recursion , num);
if ( num == 0 || num == 1 ){
printf(factorial = 1 when returning at num = =%d , num);
return 1;
}
tmp=num * factorial( num 1 );
printf(factorial = %d when returning at num = =%d , tmp, num);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started