10.6k views
22 votes
Write a code about Sum of Natural Numbers using loop in c++

User Bill Bell
by
4.4k points

1 Answer

4 votes

Answer:

Sum of Natural Numbers using loop #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; } Output. Enter a positive integer: 50 Sum = 1275

Step-by-step explanation:

User Mightimaus
by
3.9k points