josiftepe

Untitled

Oct 18th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     // korisnikot ni vnesuva eden broj n, i sakame da go prestame zbirot od site broevi pomali ili ednakvi od N pocnuvajki od 1
  8.     // N  = 5, zbir = 1 + 2 + 3 + 4 + 5
  9.     int N;
  10.     cin >> N;
  11.     int zbir = 0;
  12.     int x = 1;
  13.     int y = N;
  14.     while(x <= y) {
  15.         cout << x << " ";
  16.         zbir += x;
  17.         x += 1;
  18.     }
  19.     cout << endl;
  20.     cout << zbir << endl;
  21.     return 0;
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment