Home » Program to find the sum of Even Numbers

Program to find the sum of Even Numbers

by Online Tutorials Library

Write a program to find the sum of even numbers

In this article, we will discuss the program to find the sum of even numbers in different programming languages.

But before writing the programs, let’s first see a brief description of even numbers and the formula to find the sum of even numbers.

Even numbers

Any integer number that is completely divided by 2 is known as the even number. All the even numbers must be divided by 2. To check whether the given integer number is an odd number or an even number; we have to check the number’s last digit. The even numbers always end with the last digit of 0, 2, 4, 6, and 8.

Sum of even numbers

It is easy to find the sum of even numbers from 2 to infinity. It can be obtained by using the formula for finding the sum of natural numbers or by using the arithmetic progression.

We can use the formula n(n+1) to find the sum of even numbers, where n is any natural number. For instance, if we have to find the sum of the first four even numbers 2, 4, 6, and 8, the value of n will be 4.

i.e. sum of first four even numbers = 2 + 4 + 6 + 8 = 20

or, = 4(4+1) = 4 * 5 = 20 (n = 4)

If we have to find the sum of first three even numbers that are 2, 4, and 6, then the value of n will be 3. So,

3(3+1) = 12

Or, 2 + 4 + 6 = 12

Now, let’s see the programs to find the sum of even numbers.

Programs to find the sum of even numbers

Program: Write a program to find the sum of even numbers in C language.

Output

Write a program to find the sum of even numbers

Program: Write a program to find the sum of even numbers in the C# language.

Output

Write a program to find the sum of even numbers

Program: Write a program to find the sum of even numbers in JavaScript.

Output

After the execution of the above code, the output will be –

Write a program to find the sum of even numbers

After entering the value and clicking on OK, the output will be –

Write a program to find the sum of even numbers

Program: Write a program to find the sum of even numbers in Java.

Output

Write a program to find the sum of even numbers

Program: Write a program to find the sum of even numbers in python.

Output

Write a program to find the sum of even numbers

Program: Write a program to find the sum of even numbers in PHP.

Output

Write a program to find the sum of even numbers

So, that’s all about the article. Here, we have discussed the program to find the sum of even numbers in C, Java, C#, PHP, Python, and JavaScript. Hope you find the article helpful and informative.


Next TopicPrograms List

You may also like