I'm working with Kochan's Programming in C. I am working in Visual Studio 2008. When I try to build the program I get
Error 2 error C2143: syntax error : missing ';' before 'type' c:\users\michael\documents\visual studio 2008\projects\cpractice\cpractice\char.c 15 CPractice
But as far as I'm aware there is no syntax error. It seems the issue is declaring the array after the printf and scanf functions have been called. If I put
unsigned long long int Fibonacci[5];
before the function calls, it works fine. Put it after, error.
#include<stdio.h>
int main (void)
{
int i, numFibs;
printf("How many Fibonacci numbers do you want (between 1 and 75)? ");
scanf("%i", &numFibs);
if (numFibs < 1 || numFibs > 75) {
printf("Bad number, sorry!\n");
return 1;
}
unsigned long long int Fibonacci[numFibs];
Fibonacci[0] = 0;
Fibonacci[1] = 1;
for (i=2; i<numFibs; ++i)
Fibonacci[i] = Fibonacci[i-2] + Fibonacci[i-1];
for (i=0; i<numFibs; ++i)
printf("%llu ", Fibonacci[i]);
printf("\n");
return 0;
}