fungsi fibonacci dengan 2 cara rekursif yang lain.
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int suku;
int a,b,c;
cout<<"Membuat Deret Fibonacci\n";
cout<<"Masukkan nilai suku ke-: ";cin>>suku;
cout<<"Bilangannya adalah: \n";
a=0;b=1;
cout<<a<<endl<<b<<endl;
for(int i=3; i<=suku; i++)
{
c = a + b;
a = b;
b = c;
cout<<c<<endl;
}
return 0;
}
No comments:
Post a Comment