Generating Fibonacci Numbers Using variable-Length Arrays Code Compiler Error.

Posted by Nano HE on Stack Overflow See other posts from Stack Overflow or by Nano HE
Published on 2010-06-15T05:35:34Z Indexed on 2010/06/15 5:42 UTC
Read the original article Hit count: 192

Filed under:
|

Compile error in vs2010(Win32 Console Application Template) for the code below. How can I fix it.

unsigned long long int Fibonacci[numFibs]; // error occurred here

error C2057: expected constant expression

error C2466: cannot allocate an array of constant size 0

error C2133: 'Fibonacci' : unknown size

Complete code attached(It's a sample code from programming In c -3E book. No any modify)

int main()
{

 int i, numFibs;

 printf("How may Fibonacci numbers do you want (between 1 to 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; // by definition
 Fibonacci[1] = 1; // ditto

 for ( i = 2; i < numFibs; ++i)
  Fibonacci[i] = Fibonacci[i-2] + Fibonacci[i-1];

 for ( i = 0; i < numFibs; ++i)
  printf("%11u",Fibonacci[i]);

 printf("\n");

 return 0;

}

© Stack Overflow or respective owner

Related posts about c

    Related posts about array