Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago