C++ program to find the sum of n numbers using for loop

C++ program to find the sum of n numbers using for loop. Check the year is leap or not program in C++. This program will check the year whether it is leap year or not. This program will print the set of multiple number to add in a single program in c++ programming language

#include <iostream>
using namespace std;
int main()
{
int i,n, sum = 0;
cout << "Enter the number";
cin >> n;
for (i = 1; i <= n; ++i)
{
sum += i;
}
cout << "Sum = " << sum;
return 0;
}

Output:

Enter the number

44

Sum = 990

What is for loop and how it works

A loop is used to continually execute a set of statements until a certain condition is met. When showing numbers from 1 to 100, for example, you might wish to set the value of a variable to 1 and display it 100 times, raising its value by 1 with each loop iteration.