5
Good afternoon gentlemen
I need to make an algorithm with a procedure that takes a variable by reference and then updates the value of the variable to its corresponding factorial.
That’s the algorithm I made:
#include<stdio.h>
int fatorial(int *n){
if ((*n==1) || (*n==0)) return 1;
else return fatorial(*n-1)*n;
}
int main(){
int n = 5;
printf("%d\n",fatorial (&n));
}
But you’re making a mistake on the line:
else return fatorial(*n-1)*n;
Error:
[Warning] passing argument 1 of 'fatorial' makes pointer from integer without a cast
[Note] expected 'int *' but argument is of type 'int'
[Error] invalid operands to binary * (have 'int' and 'int *')
Can someone help me solve this problem?
the argument needs to be a pointer?
– Matheus Francisco
yes... You need to pass the memory address of the
– Arthur