Chain Chronicle

Sabtu, 28 Maret 2015

C++ bilangan Fibonacci

#include <iostream>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
long batas;
cout<<"Masukkan Batas : ";
cin>>batas;
cout<<"Bilangan Fibonacci < "<<batas;
long f1=0,f2=1;
while(true)
{long f3=f2+f1;
if(f2>batas)break;
cout<<","<<f2;
f1=f2;
f2=f3;
}
return 0;
}

Tidak ada komentar:

Posting Komentar