It was harder than another challenge, but i got this (i think), follow the code:
Code:
#include <stdio.h>
int factorial(int number, int *cont){
*cont = *cont+1;
if(number == 1){
return number;
}
//printf("%d",cont);
return factorial(number-1, cont) * number;
}
int main(){
int cont = 0;
int val;
scanf("%d", &val);
int result = factorial(val, &cont);
printf("%d\n%d\n", result, cont);
return 0;
}
Originally Posted by
Salem
Very good - now count how many temporary integers are created when you calculate factorial(4)
Now think how many integers exist when you try it with your int* approach.
Then, do you have another challenge?