Advertisement
mdejkic

fibonacci zadatak (Lejla)

Aug 22nd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int fib(int n)
  5. {
  6.     int a = 0, b = 1, c, i;
  7.     if (n == 0)
  8.         return a;
  9.     for (i = 2; i <= n; i++)
  10.     {
  11.         c = a + b;
  12.         a = b;
  13.         b = c;
  14.     }
  15.     return b;
  16. }
  17.  
  18. int main() {
  19.     double suma = 0;
  20.     int x, n;
  21.     cout << "Unesite x i n" << endl;
  22.     cin >> x >> n;
  23.     for (int i = 0; i < n; i++) {
  24.         suma += (fib(i) + x) / pow(x + i, i+1);
  25.     }
  26.     cout << suma << endl;
  27.  
  28.  
  29.     system("pause>0");
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement