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.
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