Kali ini saya akan membahas tentang deret Fibonacci..
Langsung saja kali ya.. mari kita mulai fengan C++ nya..
Contoh 1.
======================================
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
dikurr:
cout<<" ::PROGRAM DERET FIBONACCI::\n";
cout<<" ::Dian Kurniawan::\n";
cout<<" ::1300018156/D::\n\n";
int x=-1, y=1, z, a, jml;
cout<< "Jumlah deret Fibonacci = "; cin>> jml;
cout<< "Deret Fibonacci = \n";
for(a=1 ; a<=jml; a++)
{
z=x+y;
cout<< z <<ends;
x=y;
y=z;
}
cout<<endl<<endl;;
goto dikurr;
}
========================================
Contoh 2
========================================
#include <cstdlib>
#include <iostream>
#define true 1
using namespace std;
int main(int argc, char *argv[])
{
cout<<" ::PROGRAM DERET FIBONACCI::\n";
cout<<" ::Dian Kurniawan::\n";
cout<<" ::1300018156/D::\n\n";
int a, b, f=1, f2=1, derfib;
cout<<" inputkan deret : ";
cin>>b;
cout<<endl<<"Deret Fibonacci : "<<endl<<endl<<f;
for(a=1;a<=b-2;a++)
{
cout<<" "<<f2;
derfib=f+f2;
f=f2;
f2=derfib;
}
cout<<" "<<derfib<<endl;
cout<<endl;
system("PAUSE>>null");
return EXIT_SUCCESS;
}
===========================================
|
contoh 1 |
|
|
|
|
|
contoh 2 |
|
0 komentar:
Posting Komentar