Advertisement
jsumell

Factorial (Recursion)

Jun 24th, 2019
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. //Declaring function(s)
  4. int kertoma(int x);
  5.  
  6. int kertoma(int x) {
  7.     if (x<=0) {
  8.     return 1;
  9.     }
  10.     return (x*kertoma(x-1));
  11. }
  12. //Main Method
  13. int main(int argc, char *argv[]) {
  14.     if (argc <=1) {
  15.         printf("Syötä parametrina luku, jonka kertoman tuloksen haluat selvittää!");
  16.     }
  17.     else
  18.     {
  19.         int tulos;
  20.         int input = atoi(argv[1]);
  21.         tulos = kertoma(input);
  22.         printf("%d",tulos);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement