Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int liczba{ 2 }, n, i{ 1 }, suma{ 0 }; // n - ilość wypisywanych liczb, i - numer dodawanej liczby
- cout << "Podaj ilosc wyrazow ciagu, ktore maja zostac dodane: ";
- cin >> n;
- while (i <= n) {
- if (i % 2 == 1) {
- suma += (liczba * (-1));
- }
- else {
- suma += liczba; // suma = suma + liczba;
- }
- liczba += 3; // liczba = liczba + 3;
- ++i; // i = i + 1;
- }
- cout << "Suma podanego ciagu wynosi " << suma << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement