RE: [Dev-C++] Fibonacci numbers / unsigned long long int
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <Mat...@Ve...> - 2005-03-07 15:06:25
|
Try the option -std=c99 as one of your GCC options. The long long integer
type only works right in C99 C code. Let me know how it turns out.
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Dion
Bouwer
Sent: Sunday, March 06, 2005 9:18 PM
To: dev...@li...
Subject: [Dev-C++] Fibonacci numbers / unsigned long long int
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);
}
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
___________________________________________________________________
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
|