Hướng dẫn how do you find the sum of the first n even numbers in python? - làm thế nào để bạn tìm thấy tổng của n số chẵn đầu tiên trong python?

Số chẵn

Ngay cả các số là những con số có chênh lệch 2 đơn vị hoặc số. Nói cách khác, nếu số hoàn toàn chia hết cho 2 thì đó là một số chẵn.

Tổng số n số

Chương trình này giống với chương trình này: In tất cả các số chẵn từ 1 đến N. Sự khác biệt duy nhất là thay vì in chúng, chúng ta phải thêm nó vào một số biến tạm thời và in nó.

Hợp lý

Đầu tiên, chúng tôi khai báo một biến có thể tính vào giá trị 0, và sau đó chúng tôi sẽ sử dụng biến này để lưu trữ tổng số các số từ 1 đến N. bây giờ sau khi lấy đầu vào (n) từ người dùng, chúng tôi phải kiểm tra xem có phải Biến hiện tại của tôi, tôi có thể không có hoặc không bên trong vòng lặp. Nếu nó thậm chí là chúng ta phải thêm nó vào Biến Sum Sum Sum, nếu không thì hãy tiếp tục với vòng lặp.“i” is even or not inside the loop . If it is even we have to add it to variable ” sum ” otherwise continue with the loop.

Khi vòng lặp được hoàn thành, chúng tôi phải in biến tổng hợp có chứa tổng của tất cả các số chẵn lên đến N.

Chương trình

# Take input from user.
num = int(input("Print sum of even numbers till : "))

total = 0

for i in range(1, num + 1):

    # Check for even or not.
    if((i % 2) == 0):
        total = total + i

print("\nSum of even numbers from 1 to", num, "is :", total)

Đầu ra

Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550

Một phương pháp khác:n. The problem is to find the sum of first n even numbers.
Examples: 
 

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420

Trong phương pháp này, chúng ta phải tính toán thuật ngữ thứ n, Iterate through the first n even numbers and add them.
 

C++

#include <bits/stdc++.h>

using

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
0
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
1

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
5

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first 20 Even numbers is: 420
00

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
2
Sum of first 20 Even numbers is: 420
03

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
6

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
8

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
                 Sum of first n even numbers = n * (n + 1).
6

                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
                 Sum of first n even numbers = n * (n + 1).
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
2
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
3
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
4

Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
5
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
6
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
7
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
8

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
2
Sum of first 20 Even numbers is: 420
1

                 Sum of first n even numbers = n * (n + 1).
0

Java

Sum of first 20 Even numbers is: 420
3
Sum of first 20 Even numbers is: 420
4

Sum of first 20 Even numbers is: 420
8
Sum of first 20 Even numbers is: 420
28

Sum of first 20 Even numbers is: 420
30
Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
1
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
5

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
1
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
5

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first 20 Even numbers is: 420
00

Sum of first 20 Even numbers is: 420
5
                 Sum of first n even numbers = n * (n + 1).
2
Sum of first 20 Even numbers is: 420
03

#include <bits/stdc++.h>2

Sum of first 20 Even numbers is: 420
6

#include <bits/stdc++.h>2#include <bits/stdc++.h>5Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
1Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
4

Sum of first 20 Even numbers is: 420
5
                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
1 using8
Sum of first 20 Even numbers is: 420
04

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
68
Sum of first 20 Even numbers is: 420
00

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
68
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
0

Không gian phụ trợ: O (1) Vì sử dụng các biến không đổi & nbsp;

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
11
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
15

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

                 Sum of first n even numbers = n * (n + 1).
0

Python3

Cho một số n. Vấn đề là tìm tổng số n chẵn đầu tiên.Examples: & nbsp; & nbsp;

Cách tiếp cận ngây thơ: Lặp lại thông qua n số đầu tiên và thêm chúng. & Nbsp;

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
9

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
1
Sum of first 20 Even numbers is: 420
22
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first 20 Even numbers is: 420
4

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
2
                 Sum of first n even numbers = n * (n + 1).
3

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
26
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
13
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
23
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
42

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
222____113
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
23 Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
1

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
30
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
23
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
30
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
13 #include <bits/stdc++.h>0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
26

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
57
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
23
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
05

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
60
Sum of first 20 Even numbers is: 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
62
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
63
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
64
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
65

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
66
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
67

C#

using

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
69

Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
8
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
72

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
1
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
5

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
9

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
1
Sum of first 20 Even numbers is: 420
22
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first 20 Even numbers is: 420
4

#include <bits/stdc++.h>2

Sum of first 20 Even numbers is: 420
6

#include <bits/stdc++.h>2

Sum of first 20 Even numbers is: 420
8

Sum of first 20 Even numbers is: 420
5
                 Sum of first n even numbers = n * (n + 1).
0

Sum of first 20 Even numbers is: 420
5
                 Sum of first n even numbers = n * (n + 1).
2
                 Sum of first n even numbers = n * (n + 1).
3

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
1 using8
Sum of first 20 Even numbers is: 420
04

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
0

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
11
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
3
Sum of first 20 Even numbers is: 420
13

Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
5
Sum of first 20 Even numbers is: 420
15
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
7
Sum of first 20 Even numbers is: 420
17

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

                 Sum of first n even numbers = n * (n + 1).
0

PHP

Sum of first 20 Even numbers is: 420
21

Sum of first 20 Even numbers is: 420
22
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Sum of first 20 Even numbers is: 420
24
Sum of first 20 Even numbers is: 420
25

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
28
Sum of first 20 Even numbers is: 420
29

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
31
Sum of first 20 Even numbers is: 420
32

Is

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
31
Sum of first 20 Even numbers is: 420
46
Sum of first 20 Even numbers is: 420
28Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
4

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
28
Sum of first 20 Even numbers is: 420
51

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
2
Sum of first 20 Even numbers is: 420
31Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
4

                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
24
Sum of first 20 Even numbers is: 420
61

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
63
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
3
Sum of first 20 Even numbers is: 420
65
Sum of first 20 Even numbers is: 420
24
Sum of first 20 Even numbers is: 420
65
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
7
Sum of first 20 Even numbers is: 420
69
Sum of first 20 Even numbers is: 420
24
Sum of first 20 Even numbers is: 420
71

Sum of first 20 Even numbers is: 420
72

JavaScript

Sum of first 20 Even numbers is: 420
73

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
22
Sum of first 20 Even numbers is: 420
76

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
80

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
1
Sum of first 20 Even numbers is: 420
83

#include <bits/stdc++.h>2

Sum of first 20 Even numbers is: 420
6

#include <bits/stdc++.h>2

Sum of first 20 Even numbers is: 420
8

Sum of first 20 Even numbers is: 420
5
                 Sum of first n even numbers = n * (n + 1).
0

Sum of first 20 Even numbers is: 420
5
                 Sum of first n even numbers = n * (n + 1).
2
                 Sum of first n even numbers = n * (n + 1).
3

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
96

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
1 using8
Sum of first 20 Even numbers is: 420
04

                 Sum of first n even numbers = n * (n + 1).
04

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
0

Sum of first 20 Even numbers is: 420

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
11
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
3
Sum of first 20 Even numbers is: 420
13
O(n)

Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
5
Sum of first 20 Even numbers is: 420
15
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
7
Sum of first 20 Even numbers is: 420
17
O(1)

PHP By applying the formula given below. 
 

                 Sum of first n even numbers = n * (n + 1).

Proof:   
 

Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)

C++

#include <bits/stdc++.h>

Sum of first 20 Even numbers is: 420
22
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Sum of first 20 Even numbers is: 420
24
Sum of first 20 Even numbers is: 420
25

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
28
Sum of first 20 Even numbers is: 420
29

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
31
Sum of first 20 Even numbers is: 420
32

                 Sum of first n even numbers = n * (n + 1).
0

Is

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
31
Sum of first 20 Even numbers is: 420
46
Sum of first 20 Even numbers is: 420
28Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
4

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
28
Sum of first 20 Even numbers is: 420
51

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
2
Sum of first 20 Even numbers is: 420
31Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
4

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
24
Sum of first 20 Even numbers is: 420
61

                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4 Output : 20 Sum of first 4 even numbers = (2 + 4 + 6 + 8) = 20 Input : n = 20 Output : 4207Sum of first 20 Even numbers is: 42063 Sum of first n terms of an A.P.(Arithmetic Progression) = (n/2) * [2*a + (n-1)*d].....(i) where, a is the first term of the series and d is the difference between the adjacent terms of the series. Here, a = 2, d = 2, applying these values to eq.(i), we get Sum = (n/2) * [2*2 + (n-1)*2] = (n/2) * [4 + 2*n - 2] = (n/2) * (2*n + 2) = n * (n + 1)3Sum of first 20 Even numbers is: 42065Sum of first 20 Even numbers is: 42024Sum of first 20 Even numbers is: 42065Sum of first n terms of an A.P.(Arithmetic Progression) = (n/2) * [2*a + (n-1)*d].....(i) where, a is the first term of the series and d is the difference between the adjacent terms of the series. Here, a = 2, d = 2, applying these values to eq.(i), we get Sum = (n/2) * [2*2 + (n-1)*2] = (n/2) * [4 + 2*n - 2] = (n/2) * (2*n + 2) = n * (n + 1)7Sum of first 20 Even numbers is: 42069Sum of first 20 Even numbers is: 42024Sum of first 20 Even numbers is: 42071

JavaScript

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
22
Sum of first 20 Even numbers is: 420
76

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
1
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
5

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
9

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
1
Sum of first 20 Even numbers is: 420
22
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first 20 Even numbers is: 420
4

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Sum of first 20 Even numbers is: 420
5
                 Sum of first n even numbers = n * (n + 1).
2
                 Sum of first n even numbers = n * (n + 1).
3

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
1 using8
Sum of first 20 Even numbers is: 420
04

                 Sum of first n even numbers = n * (n + 1).
77
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
15

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

                 Sum of first n even numbers = n * (n + 1).
0

Python3

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
1 using8
Sum of first 20 Even numbers is: 420
04

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
57
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
23
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
05

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
60
Sum of first 20 Even numbers is: 420
2
                 Sum of first n even numbers = n * (n + 1).
97
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
63
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
64
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
65

Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
01
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
67

C#

using

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
69

Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
8
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
72

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
1
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
5

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
9

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
1 using8
Sum of first 20 Even numbers is: 420
04

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
0

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
11
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
3
Sum of first 20 Even numbers is: 420
13

Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
5
Sum of first 20 Even numbers is: 420
15
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
7
Sum of first 20 Even numbers is: 420
17

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

                 Sum of first n even numbers = n * (n + 1).
0

PHP

Sum of first 20 Even numbers is: 420
21

Sum of first 20 Even numbers is: 420
22
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Sum of first 20 Even numbers is: 420
24
Sum of first 20 Even numbers is: 420
25

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
28
Sum of first 20 Even numbers is: 420
29

                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
31
Sum of first 20 Even numbers is: 420
32

Is

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
31
Sum of first 20 Even numbers is: 420
46
Sum of first 20 Even numbers is: 420
28Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
4

Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
66
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Sum of first 20 Even numbers is: 420
24
Sum of first 20 Even numbers is: 420
71

Sum of first 20 Even numbers is: 420
72

JavaScript

Sum of first 20 Even numbers is: 420
73

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
22
Sum of first 20 Even numbers is: 420
76

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
31
Sum of first 20 Even numbers is: 420
32

                 Sum of first n even numbers = n * (n + 1).
0

Sum of first 20 Even numbers is: 420
96

Is

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
31
Sum of first 20 Even numbers is: 420
46
Sum of first 20 Even numbers is: 420
28Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
4

Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
66
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
15

                 Sum of first n even numbers = n * (n + 1).
04

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
0

Sum of first 20 Even numbers is: 420

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
11
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
3
Sum of first 20 Even numbers is: 420
13
O(1).

Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
5
Sum of first 20 Even numbers is: 420
15
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
7
Sum of first 20 Even numbers is: 420
17
: O(1) since using constant variables

PHP

Sum of first 20 Even numbers is: 420
22
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Sum of first 20 Even numbers is: 420
24
Sum of first 20 Even numbers is: 420
25

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
28
Sum of first 20 Even numbers is: 420
29Tn = a+(n-1)d, here, a= first term, d= common difference, n= number of term

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
31
Sum of first 20 Even numbers is: 420
32

Is Sn=(N/2) * (a + Tn), here a= first term, Tn= last term, n= number of term

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
31
Sum of first 20 Even numbers is: 420
46
Sum of first 20 Even numbers is: 420
28Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
4

C++

#include <bits/stdc++.h>

Sum of first 20 Even numbers is: 420
22
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Sum of first 20 Even numbers is: 420
24
Sum of first 20 Even numbers is: 420
25

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
5

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first 20 Even numbers is: 420
00

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
2
Sum of first 20 Even numbers is: 420
03

                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
                 Sum of first n even numbers = n * (n + 1).
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
2
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
3
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
4

Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
5
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
6
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
7
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
8

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
2
Sum of first 20 Even numbers is: 420
1

                 Sum of first n even numbers = n * (n + 1).
0

Java

Sum of first 20 Even numbers is: 420
3
Sum of first 20 Even numbers is: 420
24

Sum of first 20 Even numbers is: 420
3
Sum of first 20 Even numbers is: 420
4

Sum of first 20 Even numbers is: 420
8
Sum of first 20 Even numbers is: 420
28

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Sum of first 20 Even numbers is: 420
30
Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
1
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
5

Sum of first 20 Even numbers is: 420
30
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first 20 Even numbers is: 420
41Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
1
Sum of first 20 Even numbers is: 420
43#include <bits/stdc++.h>0
Sum of first 20 Even numbers is: 420
45Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
1Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
4

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
2
Sum of first 20 Even numbers is: 420
50Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
1
Sum of first 20 Even numbers is: 420
525Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
1
Sum of first 20 Even numbers is: 420
54

Sum of first 20 Even numbers is: 420
30
Sum of first 20 Even numbers is: 420
56

Sum of first 20 Even numbers is: 420
30
Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
1 using8
Sum of first 20 Even numbers is: 420
61

Sum of first 20 Even numbers is: 420
30
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
04
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
05Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
4

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
08
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
3
Sum of first 20 Even numbers is: 420
72
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
7
Sum of first 20 Even numbers is: 420
74

Sum of first 20 Even numbers is: 420
30
                 Sum of first n even numbers = n * (n + 1).
0

                 Sum of first n even numbers = n * (n + 1).
0

Python3

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
19
Sum of first 20 Even numbers is: 420
79

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
81
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
23 Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
1
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
13
Sum of first 20 Even numbers is: 420
85
Sum of first 20 Even numbers is: 420
86#include <bits/stdc++.h>0
Sum of first 20 Even numbers is: 420
25
                 Sum of first n even numbers = n * (n + 1).
87__71

Is

Sum of first 20 Even numbers is: 420
05
Sum of first 20 Even numbers is: 420
06
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
23
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
23
Sum of first 20 Even numbers is: 420
09
Sum of first 20 Even numbers is: 420
10

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
57
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
23
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
05Print sum of even numbers till : 100
Sum of even numbers from 1 to 100 is : 2550
4

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
60__2222222222222222222

C#

using

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
69

Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
8
Sum of first 20 Even numbers is: 420
27

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
1
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
3
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
5

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first 20 Even numbers is: 420
00

Sum of first 20 Even numbers is: 420
5
                 Sum of first n even numbers = n * (n + 1).
2
Sum of first 20 Even numbers is: 420
03

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
7
Sum of first 20 Even numbers is: 420
1 using8
Sum of first 20 Even numbers is: 420
04

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Sum of first 20 Even numbers is: 420
5
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
2
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
0

Sum of first 20 Even numbers is: 420
5
Sum of first 20 Even numbers is: 420
55
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
3
Sum of first 20 Even numbers is: 420
72
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
7
Sum of first 20 Even numbers is: 420
74

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
0

                 Sum of first n even numbers = n * (n + 1).
0

JavaScript

Sum of first 20 Even numbers is: 420
73

Sum of first 20 Even numbers is: 420
22
Sum of first 20 Even numbers is: 420
76

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
6

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
68
Sum of first 20 Even numbers is: 420
00

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
                 Sum of first n even numbers = n * (n + 1).
2
Sum of first 20 Even numbers is: 420
03

                 Sum of first n even numbers = n * (n + 1).
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
68
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
0

Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20 

Input : n = 20
Output : 420
7
Sum of first 20 Even numbers is: 420
98
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
3
Sum of first 20 Even numbers is: 420
72
Sum of first n terms of an A.P.(Arithmetic Progression)
= (n/2) * [2*a + (n-1)*d].....(i)
where, a is the first term of the series and d is
the difference between the adjacent terms of the series.

Here, a = 2, d = 2, applying these values to eq.(i), we get
Sum = (n/2) * [2*2 + (n-1)*2]
    = (n/2) * [4 + 2*n - 2]
    = (n/2) * (2*n + 2)
    = n * (n + 1)
7
Sum of first 20 Even numbers is: 420
74

Sum of first 20 Even numbers is: 420
83
                 Sum of first n even numbers = n * (n + 1).
04

Đầu ra

Sum of first 20 Even numbers is: 420

Độ phức tạp về thời gian: O (1).O(1).

Không gian phụ trợ: O (1) Vì sử dụng các biến không đổi & nbsp;: O(1) since using constant variables