Well, since other people are going to post code, let me show you a program that will actually work correctly:
Code:
#include <stdio.h>
int main(void)
{
int i, j;
int num;
// Outer loop - We want 10 different calculations
for(i = 1;i <= 10;++i)
{
// Initialize num to 1 every time through the outer loop
num = 1;
// Inner loop - Do the actual factorial calculation
for(j = 1;j <= i;++j)
num *= j;
// Print the result - Once each time through the outer loop
printf("%d\t%d\n", i, num);
}
return 0;
}
Code:
itsme@itsme:~/C$ ./factorial
1 1
2 2
3 6
4 24
5 120
6 720
7 5040
8 40320
9 362880
10 3628800
itsme@itsme:~/C$
FillYourBrain's method is more efficient (it works with only having 1 loop), but I think having the 2 loops is a bit easier to understand. In algorithm-effeciency terms, FillYourBrain's method is O(n) and mine is O(n^2)