C++ Program to print sum of first 10 natural numbers


In this program, You will learn how to print the sum of the first 10 natural numbers in C++.


1 + 2 + 3 + ... + 10 = 55

Example: How to print the sum of the first 10 natural numbers in C++.

#include<iostream>
using namespace std;

int main() {

    int i, s = 0;

    for (i = 1; i <= 10; i++) {
        s = s + i;
    }
    cout << "Sum of First 10 natural numbers is:" << s;

    return 0;
}

Output:

Sum of First 10 natural numbers is:55