Advertisement
Spocoman

06. Sum of Odd Numbers

Nov 2nd, 2023
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n, sum = 0;
  7.     cin >> n;
  8.  
  9.     for (int i = 1; i < n * 2; i += 2) {
  10.         cout << i << endl;
  11.         sum += i;
  12.     }
  13.  
  14.     cout << "Sum: " << sum << endl;
  15.     return 0;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement