Advertisement
MeehoweCK

Untitled

Jan 22nd, 2024
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int liczba{ 2 }, n, i{ 1 }, suma{ 0 };      // n - ilość wypisywanych liczb, i - numer dodawanej liczby
  7.     cout << "Podaj ilosc wyrazow ciagu, ktore maja zostac dodane: ";
  8.     cin >> n;
  9.  
  10.     while (i <= n) {
  11.         if (i % 2 == 1) {
  12.             suma += (liczba * (-1));
  13.         }
  14.         else {
  15.             suma += liczba;     // suma = suma + liczba;
  16.         }
  17.         liczba += 3;            // liczba = liczba + 3;
  18.         ++i;                    // i = i + 1;
  19.     }
  20.  
  21.     cout << "Suma podanego ciagu wynosi " << suma << endl;
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement