fork download
  1. #include <stdio.h>
  2.  
  3. /* 階乗を求める関数(再帰なし) */
  4. int fact(int n)
  5. {
  6. int result = 1;
  7. int i;
  8.  
  9. for(i = 1; i <= n; i++) {
  10. result *= i;
  11. }
  12.  
  13. return result;
  14. }
  15.  
  16. int main(void)
  17. {
  18. int i;
  19.  
  20. /* 1~10の階乗を表示 */
  21. for(i = 1; i <= 10; i++) {
  22. printf("%d! = %d\n", i, fact(i));
  23. }
  24.  
  25. return 0;
  26. }
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