Sabtu, 25 Juni 2011

Program C++ Deret Fibonacci

At this time we will learn to make a program about the Fibonacci series. Previously I will tell you about the Fibonacci series.
The Fibonacci sequence was discovered by Leonardi Pisano or better known as Leonardo Fibonacci (derived from Filius Bonaccio or child of Bonaccio, the designation for the father whose real name is Guglielmo), in the 12th century in Italy. Basically, the Fibonacci series is a simple number sequence starting from 0 and 1 and the subsequent interest is the sum of the two previous numbers. Fibonacci sequence is recursive because it uses terms in the series to calculate the rate thereafter. By definition, then the tribes on the Fibonacci series is:

0 1 1 2 3 5 8 13 21 34 55 89 144 and so on.
The ratio of a pair of successive interest in the Fibonacci series will converge to an irrational number 1.618 or phi (Φ). Phi is an irrational constant value 1.61803399 ... in the can from the ratio kenvergensi tribe against tribe in the Fibonacci series sbelumnya. In the Fibonacci series, a tribe is the sum of the two tribes before. Known ratio of two consecutive rate converges to a value, consider the value of the variable p. So the sequence of interest is very large, eg 3 consecutive rate is denoted as a, b, and c, then applies:

c / b = b / a = p; with c = a + b

-> (A + b) / b = b / a;

-> A ^ 2 + ab = b ^ 2;

-> A ^ 2 + ab-b ^ 2 = 0; press. quadratic

-> Then obtained a / b = (1 + √ 5) / 2 or a / b = (1 - √ 5) / 2

-> If calculated, (1 + √ 5) / 2 is equivalent to 1.618 ... while (1 - √ 5) / 2 is equivalent to 0.618 .... Since a1, 618 ...

Thus the number phi has properties, a number which is the number itself resiproknya minus 1. (1/phi = phi-1).
Numbers Phi is said by experts as the divine proportion or the proportion of noble or dalah term more popularly known sebagain golden ratio. Divine proportion was as if God put it into his creation to prove his greatness by the beauty of nature. There are so many examples of the appearance of golden ratio in the universe, ranging from the finger that we use for typing, outer space until there.
n                          : integer             (input)
fibbonaci             : integer             (output)
if (n = 1) or (n = 2) then
fibbonaci <= 1
fibbonaci <= fibbonaci(n-1) + fibbonaci(n-2)

Berikut kode programnya :

#include <cstdlib>
#include <iostream>

using namespace std;
class fibonacci{
      friend istream& operator>>(istream&, fibonacci&);
      friend ostream& operator<<(ostream&, fibonacci&);
             void proses();
             void jumlah();
              int x[100];
              int a,hasil;
      istream& operator>>(istream& mlebu, fibonacci& s){
               cout<<"Masukkan Banyak Suku :"; mlebu>>s.a;
      ostream& operator<<(ostream& metu, fibonacci& v){
               metu<<"Suku Fibonacci :"<<v.a<<endl;
               metu<<"Deret Fibonacci :";
               for(int i=0; i<v.a; i++){
               metu<<"Hasil Jumlah Deret Fibonacci :"<<v.hasil<<endl;
                             cout<<"\t\t<< PROGRAM MENCETAK DAN MENGHITUNG DERET FIBONACCI >>"<<endl;
      void fibonacci::proses(){
           if(a==1) hasil=1;
           else if(a==2) hasil=1;
           for(int i=2; i<a; i++){
      void fibonacci::jumlah(){
            for(int i=0; i<a; i++){
int main(int argc, char *argv[])
    fibonacci x;
    return EXIT_SUCCESS;
Above program is a program to calculate the Fibonacci sequence is by using a for loop and the selection / conditioning if .. else. And the Fibonacci sequence is one example of a recursive program by having the two terms are penyetop cases and cases of a function call itself can be seen in the algorithm above.

1 komentar:

newbie guba mengatakan...

kurang jelas penjelasanya..
info seputar bola, prediksi bola ter-update..
berita bola TERBARU DAN TERPERCAYA hanya ada di

Poskan Komentar

Template by:

Free Blog Templates