josiftepe

Untitled

Jan 27th, 2021
74
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. using namespace std;
  3.  
  4. int main() {
  5.  
  6.     int k;
  7.     cin >> k;
  8.    
  9.     int pocetok = 1;
  10.     int zbir = 0;
  11.     // pocetok = 1, i = 1
  12.     // pocetok = 1 + 3 = 4, i = 2
  13.     // pocetok = 4 + 3 = 7, i = 3
  14.     // pocetok = 7 + 3 = 10, i = 4
  15.     for(int i = 1; i <= k; i++) { // za site broevi od 1 do k
  16.         zbir += pocetok;
  17.         pocetok += 3; // 1 + 3 = 4
  18.         // 4 + 3 = 7
  19.         // 7 + 3 = 10
  20.         // 10 + 3 = 13 ...
  21.     }
  22.     cout << zbir << endl;
  23.    
  24.     return 0;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment