Advertisement
BojidarDosev

Arithmetic progression

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