The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled C Code
Posted by: memoizedfib | August 30, 2010 @ 3:33am
C Code
[
Download
]
#include <stdio.h> #define MEMO 92 long long unsigned int memoize[MEMO]; void memoInit(){ int i; for(i=0;i<MEMO;i++) memoize[i]=-1; memoize[0]=1; memoize[1]=1; } long long unsigned int fib(int x){ long long unsigned int ans; if(memoize[x]==-1){ ans = fib(x-1) + fib(x-2); memoize[x] = ans; } return memoize[x]; } void main(){ int x; memoInit(); printf("Calculates Fib[x].\n"); printf("Choose x < 0 to quit.\n\n"); printf("x: "); scanf("%d", &x); while(x>=0){ if(x>(MEMO-1)) printf("x must be less than %d\n", MEMO); else printf("Fib[%d]=%lld\n",x, fib(x)); printf("x: "); scanf("%d", &x); } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.58 / 8
67 Votes
http://codebin.yi.org/817
page generated in 0.01 seconds