Advertisement
kadoel

C++ Deret Fibonnaci

Nov 4th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <conio>
  4.  
  5. #include <stdlib>
  6.  
  7.  
  8.  
  9. int fibonacci(int deret)
  10.  
  11. {
  12.  
  13.     if (deret==0 || deret==1)
  14.  
  15.     return deret;
  16.  
  17.    else
  18.  
  19.     return fibonacci(deret -1) + fibonacci (deret -2);
  20.  
  21. }
  22.  
  23.  
  24.  
  25. main()
  26.  
  27. {
  28.  
  29.     atas:
  30.  
  31.     int hasil, deret;
  32.  
  33.    char ans;
  34.  
  35.    cout<<"Masukkan Suku Deret ke : "; cin>>deret;
  36.  
  37.    hasil=fibonacci(deret);
  38.  
  39.    cout<<"Hasil Deret Fibonacci  : "<<hasil<<endl<<endl;
  40.  
  41.    lagi:
  42.  
  43.    cout<<"Apakah Anda Ingin Mencoba Lagi [Y/N] : "; cin>>ans;
  44.  
  45.    if (ans=='y' || ans=='Y')
  46.  
  47.     {  system ("cls"); goto atas;}
  48.  
  49.  
  50.  
  51.    if (ans=='n' || ans=='N')
  52.  
  53.     { system ("cls"); cout<<"=*= TERIMAKASIH =*="; }
  54.  
  55.  
  56.  
  57.    else { system ("cls"); goto lagi; }
  58.  
  59.    getch();
  60.  
  61.  
  62.  
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement