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;
}
you should set stop if
:
int faktorijel(int x){
if (x == 1) {
return 1;
} else {
return (x*faktorijel(x-1));
}
}
User contributions licensed under CC BY-SA 3.0