피보나치 수열 소스코드: Difference between revisions
From CS Wiki
No edit summary |
(→C언어) |
||
Line 2: | Line 2: | ||
<syntaxhighlight lang="C" line='line'> | <syntaxhighlight lang="C" line='line'> | ||
#include <stdio.h> | #include <stdio.h> | ||
int dp[100]; | |||
int fib(int n) { | int fib(int n) { | ||
if(dp[n]) return dp[n]; | |||
if(n<=1) return n; | if(n<=1) return n; | ||
else return fib(n-1)+fib(n-2); | else return dp[n] = fib(n-1)+fib(n-2); | ||
} | } | ||
Latest revision as of 11:40, 10 July 2019
C언어[edit | edit source]
#include <stdio.h>
int dp[100];
int fib(int n) {
if(dp[n]) return dp[n];
if(n<=1) return n;
else return dp[n] = fib(n-1)+fib(n-2);
}
int main() {
printf("%d", fib(35));
}