Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part of study guide, i need the answers. 61. Complete the following program; thi

ID: 3903572 • Letter: P

Question

Part of study guide, i need the answers.

61. Complete the following program; this program should display a random integer value between a minimum and maximum value (inclusive specified by the user. #include #include #include using namespace std; int main() int min, max; srand(time()); cout min; cout max; return ; 62. Define the body of factorial, this function shall return the factorial of x or 1 if x is less than or equal to 1. Examples: factorial of O is 1, factorial of 1 is 1, factorial of 3 is 3*2*1 = 6, factorial of 4 is 4*3*2*1 = 24, factorial of 5 is 5*4*3*2*1 = 120. int factorial(int x)

Explanation / Answer

61. As C does not have an inbuilt function for generating a number in the range, but it does have rand function which generate a random number from 0 to RAND_MAX. With the help of rand () a number in range can be generated as num = (rand() % (upper – lower + 1)) + lower

This will help you to generate random numbers within your given range.

62. You can use below function for calculating factorial.

int factorial(int x) {

if (x == 0 || x == 1) //this would check if the number x is equal to 0 or 1, then its factorial must be 1 as required.

return 1;

return x*factorial(x-1); // this would call the factorial function recursively to generate the factorial value of the given number x.

}

Here we are calling factorial function recursively to generate required factorial.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote