Hi there. I'm trying to write up a simple factorial code yet i'm finding it difficult to get around.
Here is the code i have so far
Code:
#include <stdio.h>
int main() {
int num, sum, dum;
num = 1;
printf("Enter number: ");
scanf("%d", &sum);
dum = sum;
while(num <= dum) {
sum = sum * num;
num = num + 1;
}
printf("Sum = %d\n", sum);
return 0;
}
Now it goes through it in the right way, just that when it comes to the answer it should output, it multiplies it again by the initial sum number. So if i put in to find 3! it produces 18 (ie, the answer should be 6, yet it multiplies by 3 one last time). Sorry if it is obvious, i'd stay around to figure it out but i have to leave. Thanks.