Kasus 5.6
//SELAMAT MENCOBA YA:
#include <iostream>
#include <string>
using namespace std;
void fibonacci(int n,int f1,int f2,int x){
int f3;
if(x>(n-2)){
}
else{
f3=f1+f2;
cout<<f3<<", ";
f1=f2;
f2=f3;
x=x+1;
fibonacci(n,f1,f2,x);
}
}
int main() {
int f1;
int n;
int f2;
int x;
cout<<"masukan suku ke-n : ";
cin>>n;
cout<<"fibonacci suku ke-"<<n<<endl;
x=1;
f1=0;
f2=1;
cout<<f1<<", "<<f2<<", ";
fibonacci(n,f1,f2,x);
return 0;
}
#include <string>
using namespace std;
void fibonacci(int n,int f1,int f2,int x){
int f3;
if(x>(n-2)){
}
else{
f3=f1+f2;
cout<<f3<<", ";
f1=f2;
f2=f3;
x=x+1;
fibonacci(n,f1,f2,x);
}
}
int main() {
int f1;
int n;
int f2;
int x;
cout<<"masukan suku ke-n : ";
cin>>n;
cout<<"fibonacci suku ke-"<<n<<endl;
x=1;
f1=0;
f2=1;
cout<<f1<<", "<<f2<<", ";
fibonacci(n,f1,f2,x);
return 0;
}
//HASIL PROGRAM DI ATAS:
RAPTOR
0 komentar:
Posting Komentar