fork download
  1. /* [Exercise 1] List of factorials */
  2.  
  3. #include <stdio.h>
  4.  
  5. int main(void) {
  6. int n, i;
  7. long factorial; /* Change "int" to "long" to calculate correctly */
  8.  
  9. for( n = 1; n <= 20; n++ ) {
  10. factorial = 1;
  11. for( i = 1; i <= n; i++ ) {
  12. factorial *= i; /* same as "factorial = factorial * i" */
  13. }
  14. printf( "%d! = %ld\n", n, factorial );
  15. }
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
11! = 39916800
12! = 479001600
13! = 6227020800
14! = 87178291200
15! = 1307674368000
16! = 20922789888000
17! = 355687428096000
18! = 6402373705728000
19! = 121645100408832000
20! = 2432902008176640000