fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cout << "enter how many even numbers to sum: ";
  7. cin >> n;
  8.  
  9. int sum = 0;
  10.  
  11. for (int i = 1; i <= n; i++) {
  12. sum += 2 * i;
  13. }
  14.  
  15. cout << "the sum of the first " << n << " even numbers is " << sum << endl;
  16.  
  17. return 0;
  18. }
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
enter how many even numbers to sum: the sum of the first 22098 even numbers is 488343702