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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!