fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6.  
  7. int number;
  8. int total;
  9.  
  10. cout << "Enter a number\n";
  11. cin >> number;
  12.  
  13. total = 0;
  14.  
  15. for (int i =0; i <= number ; i++)
  16. {
  17. total += i;
  18. }
  19.  
  20. cout << "Sum of numbers from 1 to " << number << " is " << total << endl;
  21. return 0;
  22. }
Success #stdin #stdout 0s 5284KB
stdin
6
stdout
Enter a number
Sum of numbers from 1 to 6 is 21