I am working on a simple function that, given an input n, returns n Fibonacci's numbers.
int main(){
int n = 0;
int counter = 1;
int f1, f2, f3 = 1;
printf("Insert an integer bigger than 0:\n");
scanf("%i", &n);
printf("%i", f1);
while(counter <= n){
f3 = f1 + f2;
printf("%i\n", f3);
f1 = f2;
f2 = f3;
counter = counter + 1;
}
return 0;
}
Surprisingly, the function returns different results each time I run the program. Furthermore, these numbers are far bigger/smaller than any possible result.
Most likely, I am missing something obvious, but I cannot explain such a behavior.