I am currently stuck on a problem for my intro to programming class assignment. I have to write a function that calculates the factorial of a number. I know how to do that as you can see below. However The assignment is asking for:
Test you function by calling it from the main. Call the function in a loop, an output the results like this:
Factorials:
1: 1
2: 2
3: 6
4: 24
5: 120
… etc.
The function will stop working when the numbers get too large to fit in your variables. What data type should you use to calculate the most factorials?
I am totally lost at this. I wanted to know if someone could guide me in what to do? I have pasted my code below:
#include <stdio.h>
int main(void){
int number;
printf("Enter an integer: ");
scanf("%i", &number);
factorial(number);
return 0;
}
int factorial(int number){
int fac = 1, count;
count = number;
while(count > 1){
fac = fac * count;
count = count - 1;
}
printf("The factorial: %i\n", fac );
}