Write C program to find sum of even numbers between 1 to n


Introduction

Write C program to find sum of even numbers between 1 to n


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>

int main()
{
    int i, num, sum=0;
    
    // Reading number
    printf("Enter any number: ");
    scanf("%d", &num);

    for(i=2; i<=num; i+=2)
    {
        //Adding current even number to sum variable
        sum += i;
    }
    printf("Sum of all even number between 1 to %d: %d", num, sum);

    return 0;
}

Result

C language

     





Related Topics




Popular Posts