Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
getMaxWordLength().... Ben Bacarisse wins!
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="jacob navia, post: 5165641"] 1 #include <math.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #define SQRT5 2.236067977499789696409173L 5 #define MAXFIB 93 6 static unsigned long long fib(int n) 7 { 8 long double phi = (1+SQRT5)/2.0; 9 long double phi_n = pow(phi,(long double)n); 10 long double result = phi_n/SQRT5; 11 return round(result); 12 } 13 14 int main(int argc,char *argv[]) 15 { 16 unsigned int i, limit; 17 18 if (argc > 1) limit = atoi(argv[1]); 19 else limit = 50; 20 if (limit > 70) { 21 printf("Warning: Results beyond fib(70) are not accurate in the last digits\n"); 22 if (limit > MAXFIB) { 23 printf("Error, max is %d. Results beyond that are wrong\n",MAXFIB); 24 limit = MAXFIB; 25 } 26 } 27 for (i=0; i<limit; i++) { 28 printf("Fib(%d)=%llu\n",i,fib(i)); 29 } 30 return 0; 31 } [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
getMaxWordLength().... Ben Bacarisse wins!
Top