Rewrite the Factorial C program that I shared in class or yo

Rewrite the Factorial C program that I shared in class or your equivalent version of it so that it: ( THIS IS PASTED BELOW )

1. Calculates the factorials for integers from 3 through 8.

a. Values 3 & 8 should be defined as constants using either of the 2 methods for defining constants.

2. Uses for loops instead of while loops.

3. Uses the *= operator.

4. Output the results in a table containing 2 columns.

a. The first row should be a header row printing out n and n! as the column headers.

b. The subsequent rows should show the values of n and n!

c. The columns should be neatly aligned. Remember that n! means 1*2*3*…*(n-1)*n.

#include

Solution

// C code
#include <stdio.h>
#include <string.h>
#define M 3
#define N 8

int main()
{
int i, Factorial, iFactorial = 0;
printf(\" n n!\ \");

// Uses for loops
for (iFactorial = M; iFactorial <= N ; ++iFactorial)
{
Factorial = 1;
for (i = 1; i <= iFactorial; ++i)
{
// Uses the *= operator.
Factorial *= i;
}

printf(\"%5d %9d\ \",iFactorial,Factorial);
}

return 0;
}

/*
output:

n n!
3 6
4 24
5 120
6 720
7 5040
8 40320

*/

Rewrite the Factorial C program that I shared in class or your equivalent version of it so that it: ( THIS IS PASTED BELOW ) 1. Calculates the factorials for in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site