Advertisement
BojidarDosev

Geometric progression

Mar 14th, 2024
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <vector>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     // q, n, a1, an
  11.     // an - posledniq chlen ; sn - sumata na chlenovete; an1 - temp chlen
  12.     double a1, n, q, an;
  13.     double sn;
  14.     cout << "Purvit chlen e: ";cin >> a1; cout << "Chastnoto e: "; cin >> q; cout << "Broq e "; cin >> n; cout << endl;
  15.    
  16.     int n1 = n;
  17.  
  18.     vector <double> prog = {};
  19.  
  20.  
  21.     for (int i = 1; i < n+1; i++)
  22.     {
  23.         an = a1 * pow(q, i - 1);
  24.         prog.push_back(an);
  25.     }
  26.  
  27.     for (int i = 0; i <n; i++)
  28.     {
  29.         cout << prog[i] << " ";
  30.     }
  31.  
  32.     //cout << "an: " << an << endl;
  33.     //cout << "sn: " << sn << endl;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement