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 <stdio.h>
#include <conio.h>

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

    for(i=1; i<=10; i=i+1)
    {
        printf("%d\n",n);
        s=s+n;
        n=n+2;
    }
    printf("Sum of 1st 10 even numbers = %d",s);
    return 0;
}

Output

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