fork download
  1. #include <stdio.h>
  2.  
  3. int fact(int n)
  4. {
  5. if (n == 1) {
  6. return 1;
  7. } else {
  8. return n * fact(n - 1);
  9. }
  10. }
  11.  
  12. int main(void)
  13. {
  14. for (int i = 1; i <= 10; i++) {
  15. printf("%d! = %d\n", i, fact(i));
  16. }
  17.  
  18. return 0;
  19. }
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