Dremendo Tag Line

Print the sum of 1st 10 even numbers using for loop in C++

for Loop - Question 1

In this question, we will see how to print the sum of 1st 10 even numbers in C++ programming using for loop. To know more about for loop click on the for loop lesson.

Q1) Write a program in C++ to print the sum of 1st 10 even numbers using for loop.

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int i,n=2,s=0;

    for(i=1; i<=10; i=i+1)
    {
        cout<<n<<endl;
        s=s+n;
        n=n+2;
    }
    cout<<"Sum of 1st 10 even numbers = "<<s;
    return 0;
}

Output

2
4
6
8
10
12
14
16
18
20
Sum of 1st 10 even numbers = 110
video-poster