Sunday, April 10, 2016

(Fibonacci Rekursif) Program C++ Mencari bilangan Fibonacci Rekursif

  • Mencari Bilangan Fibonacci dengan Function Rekursif

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int fibo(int n){
    if((n==1) || (n==2) ) return 1;
    else return (fibo(n-1)+fibo(n-2));
}
int main(int argc, char** argv) {
    int a;
    int i;
    cout<<"Masukan N : ";cin>>a;
    for(i=1;i<=a;i++){
    cout<<fibo(i)<<" ";}
    return 0;
}


 

1 comments so far


EmoticonEmoticon

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:o
:>)
(o)
:p
:-?
(p)
:-s
8-)
:-t
:-b
b-(
(y)
x-)
(h)