August 28th, 2013, 02:52 PM
Program to compute factorials...
I need to write a program to compute factorials and store the answer in an array. It needs to handle large factorials. This is the way we were told to do this. I know I have something horribly wrong because all factorials = 0. ;)
Can someone point me in the correct direction?
int total, rem=0, count;
printf("For what factorial would you like to know the value? \n");
i = 2999;
ansArr = 1;
for(count=2; count<=num; count++)
total = ansArr[i] * count + rem;
rem = 0;
ansArr[i] = total%10;
rem = total/10;
ansArr[i] = total;
printf("%i! = %i\n", num, total);
August 29th, 2013, 01:10 AM
August 29th, 2013, 05:08 AM
ok well im also new to c but ive recently done a factorial function.
what we did was:
and i think u should have %d for ur scanf
double total = 1;
int max = num + 1;
for ( x = 2; x < max; x++ )
total = total*x;
August 29th, 2013, 05:19 PM
The %i format is valid for this problem. The big trouble was forgetting to provide output from ansArr .
[/code] are essential for python code and Makefiles!