C language recursion factoriel not working

0

For the code down below I get no response, I kept it minimal with no conditions, imagining people will choose positive number for example. It gives me no response besides Process returned -1073741571 (0xC00000FD) execution time : 3.194 s. If I type 5, answer should be 120, not here.

#include <stdio.h>
#include <stdlib.h>

int faktorijel(int x){

        return (x*faktorijel(x-1));

}
main (){

int a,b ;
printf("Type in a number:");
scanf("%d\n", &a);
b=faktorijel(a);
printf("Result is %d\n", b);
return 0;

}
c
function
recursion
asked on Stack Overflow Aug 17, 2020 by DrexxBoban • edited Aug 17, 2020 by DrexxBoban

1 Answer

1

you should set stop if:

int faktorijel(int x){
        if (x == 1) {
          return 1;
        } else {
          return (x*faktorijel(x-1));
        }
}
answered on Stack Overflow Aug 17, 2020 by No.The.Hi

User contributions licensed under CC BY-SA 3.0