I'm doing a college exercise where the user must enter a number and the program should return the Fibonacci sequence. However, according to the teacher, it should start at 0 (ZERO), but my program starts at 1.
Note: The teacher has already corrected and will not accept any further modifications, I really want to understand why my program did not print zero, since I declared a = 0
.
Program:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <locale.h>
main() {
setlocale(LC_ALL, "Portuguese");
int a, b, auxiliar, i, n;
a = 0;
b = 1;
printf("Digite um número: ");
scanf("%d", &n);
printf("\nSérie de Fibonacci:\n\n");
printf("%d\n", b);
for(i = 0; i < n; i++) {
auxiliar = a + b;
a = b;
b = auxiliar;
printf("%d\n", auxiliar);
}
}
Thanks in advance.