Mencari Bilangan Fibonacci dengan Function Rekursif
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int fibo(int n){
if((n==1) || (n==2) ) return 1;
else return (fibo(n-1)+fibo(n-2));
}
int main(int argc, char** argv) {
int a;
int i;
cout<<"Masukan N : ";cin>>a;
for(i=1;i<=a;i++){
cout<<fibo(i)<<" ";}
return 0;
}
1 comments so far
sangat membantu.
EmoticonEmoticon