Thread: 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.
|
|
From: <Mat...@Ve...> - 2005-03-07 15:08:27
|
Not quite! long long is actually an abbreviation for long long int. The compiler is supposed to look at them both as being identical tokens. -----Original Message----- From: dev...@li... [mailto:dev...@li...]On Behalf Of Alfred P. Reaud Sent: Sunday, March 06, 2005 10:46 PM To: Dev-Cpp UserList Subject: Re: [Dev-C++] Fibonacci numbers / unsigned long long int It appears you may be exceeding the length of a 32 bit int, which is what probably happened with the long long int declaration. Try declaring long long instead of long long int for Fibonacci. Interesting bug! Dion Bouwer <dio...@in...> wrote: <snip> unsigned long long int Fibonacci[numFibs]; <snip> Alfred P. Reaud ___________________________________________________________________ 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. |
|
From: <Mat...@Ve...> - 2005-03-07 15:08:54
|
Very impressive! Nice work! -----Original Message----- From: dev...@li... [mailto:dev...@li...]On Behalf Of Per Westermark Sent: Sunday, March 06, 2005 11:00 PM To: Alfred P. Reaud Cc: Dev-Cpp UserList Subject: Re: [Dev-C++] Fibonacci numbers / unsigned long long int Nothing wrong with the long long int declaration. However, MinGW is using Microsoft libraries, and the Microsoft libraries doesn't understand the "%llu" formatting parameter. Instead, "%I64u" must be used to print 64-bit numbers. Since the x86 architecture stores lowest byte first, "%llu" becomes "%lu" and the least significant 4 bytes gets printed and the most significant 4 bytes are left on the stack for following printf parameter declarations to use... /Per W On Sun, 6 Mar 2005, Alfred P. Reaud wrote: > It appears you may be exceeding the length of a 32 bit int, which is what probably happened with the long long int declaration. Try declaring long long instead of long long int for Fibonacci. Interesting bug! > > Dion Bouwer <dio...@in...> wrote: > > <snip> > > unsigned long long int Fibonacci[numFibs]; > > <snip> > > > > > Alfred P. Reaud > > > ------------------------------------------------------- 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. |