[Dev-C++] Fibonacci numbers / unsigned long long int
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Dion B. <dio...@in...> - 2005-03-07 05:18:18
|
Hello
The following code, when assembled by dev-cpp calculates the incorrect 49th Fibonacci number, which should be 4807526976. However, when compiled by another assembler (lc.exe), it works fine.
The 47th Fibonacci (1836311903) and 48th Fibonacci (2971215073) are
calculated correctly, but when they're added together to create the 49th
Fibonacci, the answer is incorrectly calculated and displayed.
Does Dev-C have to be configured in any special way to handle unsigned
long long integers?
/* Generate Fibonacci numbers using variable length arrays */
#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 ("\nNumber must be between 1 and 75!!\n");
return (1);
}
unsigned long long int Fibonacci[numFibs];
Fibonacci[0] = 0; // by definition
Fibonacci[1] = 1; // by definition
for ( i = 2; i < numFibs; ++i )
Fibonacci[i] = Fibonacci[i-2] + Fibonacci[i-1];
for ( i = 0; i < numFibs; ++i )
printf ("%llu\n", Fibonacci[i]);
printf ("\n");
return (0);
}
|