Name: ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
// A fancy C++ program that calculates n!
#include <iostream>
using namespace std;
int factorial(int);
int main() {
int num;
cout << "Enter a number: ";
cin >> num;
int fac = factorial(num);
cout << num << "! = " << fac;
return 0;
}
// Compute n!
int factorial(int n) {
int prod = 1;
for( int i = 1; i <= n; i++ ) {
prod = prod * i;
}
return prod;
}
Turn in this page, along with a printout of your code (using codeprint) and a screen capture showing it compile with gcc and showing it run twice with input 4 and 8 like so:
> Enter a number: 4 4! = 24 > Enter a number: 8 8! = 40320