#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int interatif (int x){
int c,n,first = 0, second = 1, next;
cout <<"Masukan Nilai =";cin>>n;cout<<endl;
for (c=0;c < n ; c++ )
{
if (c<=1)
next = c;
else
{
next = first + second;
first = second;
second = next;
}
cout<<next<<endl;
}
} int rekursif (int x){
int n,next,first=0,second=1;
cout <<"\nMasukan Nilai =";cin>>n;cout<<endl;
for (x=0;x<n;x++){
if (x<=1)
next=x;
else{
next = first + second;
first=second;
second=next;
}
cout<<next<<endl;
}
}
int main(int argc, char** argv) {
int x;
cout<<"Interatif ="<<interatif(x);cout<<endl;
cout<<"Recurtif ="<<rekursif (x);cout<<endl;
return 0;
}
Tidak ada komentar:
Posting Komentar