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

1.1 Calculate Factorial Write a function that calculates factorial of a number.

ID: 3623955 • Letter: 1

Question

1.1 Calculate Factorial
Write a function that calculates factorial of a number. Factorial function should
accept integer number n as input and return the factorial of a number. Proto-
type of a factorial function is: unsigned long factorial (int n). Using for
loop, print factorial for n = 0 to 10. Output should looks like as follows.
factorial output:
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
Hint: The factorial of a integer n, denoted by n!, is the product of all positive
integers less than or equal to n. For example, 5! = 5 4 3 2 1 = 120.
0! is a special case that is explicitly dened to be 1. There are many ways to
implement factorial function. You can use for loop to implement factorial.

Explanation / Answer

please rate - thanks

#include <iostream>
using namespace std;
unsigned long factorial(int );
int main()
{  
    double n;
    for(n=0;n<=10;n++)
           cout<<n<<"! = "<<factorial(n)<<endl;
      
    system("pause");
    return 0;
}
unsigned long factorial(int n)
{int i;
unsigned long f=1;
for(i=1;i<=n;i++)
    f=f*i;
return f;
}