Advertisement
wrahq

[ćw 2 / 1] Ciąg Fibbonacciego

Apr 23rd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. Zadeklaruj tablice o rozmiarze 100. Wypelnij tablice zgodnie z regulami Ciagu Fibbonacciego
  2. (pierwszy i drugi element = 1, kazdy nastepny to suma dwóch poprzednich: 1,1,2,3,5,8, itd.).
  3.    
  4.  
  5. #include<iostream>
  6. using namespace std;
  7.  
  8. int main(){
  9. cout << "Ciag Fibbonacciego" << endl << endl;
  10.    
  11.     long long int* tab = new long long int[100];
  12.     tab[0] = 1;
  13.     tab[1] = 1;
  14.    
  15.     cout << tab[0] << endl;
  16.     cout << tab[1] << endl;
  17.    
  18.     for(int i = 2; i<=100; i++){
  19.         tab[i] = tab[i-1] + tab[i-2];
  20.         cout << tab[i] << endl;
  21.     }
  22.    
  23.     cin.get();
  24.    
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement