Advertisement
MonsterScripter

CodinGame_2023_08_21__22_07_45__factorial.c

Aug 21st, 2023 (edited)
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5.  
  6. long fact(int n);
  7.  
  8. /**
  9.  * Auto-generated code below aims at helping you parse
  10.  * the standard input according to the problem statement.
  11.  **/
  12.  
  13. int main()
  14. {
  15.     int N;
  16.     scanf("%d", &N);
  17.  
  18.     // Write an answer using printf(). DON'T FORGET THE TRAILING \n
  19.     // To debug: fprintf(stderr, "Debug messages...\n");
  20.     if (N < 0) {
  21.         printf("No negative integers");
  22.     } else {
  23.         printf("%ld\n", fact(N));
  24.     }
  25.  
  26.     return 0;
  27. }
  28.  
  29. long fact(int n) {
  30.     if (n == 0 || n == 1) return 1;
  31.     return n * fact(n-1);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement