- 2

Sum of first 10 natural numbers

1st Mar 2019, 2:30 PM
Aughar Dani
Aughar Dani - avatar
2 Réponses
+ 6
#include <iostream> using namespace std; int main() { int n, sum = 0; cout << "Enter a positive integer: "; cin >> n; for (int i = 1; i <= n; ++i) { sum += i; } cout << "Sum = " << sum; return 0; }
1st Mar 2019, 4:27 PM
Ashutosh Sharma
Ashutosh Sharma - avatar
+ 3
55.
1st Mar 2019, 5:25 PM
Diego
Diego - avatar