Re: [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 13:15:03
|
Thank you for the program you sent Puime, but I've already coded=20
something similar, and yes, this approach works equally well.
However, generating Fibonacci numbers is not what this is all about.=20
This is about unsigned long long int used in arrays and the fact that=20
compiler x doesn't work but compiler y does.
Why the difference?
Is it a compiler issue or is it a Dev-C issue? My thought on the matter=20
is that it's Dev-C issue, but I'm not sure, which is why I raised the=20
question.
Can anyone else please provide some extra input?
Regards
Dion
gpuime wrote:
> Sorry ,Dion, that I didn't deal with the "real matter" yet, but=20
> "Fibonacci[numFibs];" doesn't seem legitimate to me; you must declare=20
> an array of pointers and allocate memory to it using the keyword=20
> "new". Besides I checked you results in a table and what you call 47th=20
> seems to be 46th, and so on .
> My program (here attached) has two Fibonacci functions (the recursive=20
> one is limited to smaller numbers the other goes up to the 92nd") and=20
> works all-right under Dev.C++ 1.=034.9.9.2.
> Puime.
>
> Le 7 mars 05, =E0 13:29, Dion Bouwer a =E9crit :
>
>> Puime
>>
>> I'm equally surprised that you keep avoiding the real matter at hand=20
>> here, which is that other compilers work just fine, no errors, no=20
>> warnings and the 49th Fibonacci is calculated correctly.
>>
>> "unsigned long long int Fibonacci[numFibs];" simply declares a=20
>> variable length array, which is perfectly legitimate...
>>
>> Why not compile the code using Dev-C and then use another non gcc=20
>> compiler and see the difference for yourself.
>>
>> Regards
>> Dion
>
>------------------------------------------------------------------------
>
># include <iostream>
>using namespace std ;
>
> long long fibonacci(char n){/* max n:92 */
>int i ; long long a=3D1, b=3D1, c ;
>if(n<0||n>92) return -1 ; /* <- error, */
>if(!n) return 0 ; if(n<3) return 1 ;
>for(i=3D2;i<n;i++) c=3Da , a+=3Db , b=3Dc ; return a ; }
>
> long fib(char n){ /* recursive, max n=3D40 */
>if(n<1||n>40) return -1 ;
>if(!n) return 0 ; if(n<3) return 1 ;
>return fib(n-2)+fib(n-1) ; }
>
> int main(){ bool e ; int x ; long long f ;
>cout<<"Fibonacci series"<<endl ;
>do{
> cout<<"enter a small number or zero to end : " ;
> do{ e=3D0 ;
> if(!(cin>>x))
> e=3D1 , cin.clear() ,
> cout<<"wrong input, try again : " ;
> cin.ignore(80,'\n') ;
> }while(e) ;
> f=3Dfibonacci(x) ;
> if(f>=3D0) cout<<"Fibonacci-> "<<fibonacci(x)<<endl ;
> else cout<<"no Fibonacci"<<endl ;
> f=3Dfib(x) ;
> if(f>=3D0) cout<<"recursive Fib -> "<<fib(x)<<endl ;
> else cout<<"no recursive Fib"<<endl ;
> cout<<endl ;
>}while(x>0) ;
>return 0 ; }
> =20
>
|