8916. First even

 

Given a positive integer n. Print the first n even positive integers in ascending order.

 

Input. One single positive integer n.

 

Output. Print the first n even positive integers in a single line.

 

Sample input

Sample output

3

2 4 6

 

 

SOLUTION

loop

 

Algorithm analysis

Print the first n even positive integers in ascending order.

 

Algorithm implementation

Read the input value of n.

 

scanf("%d", &n);

 

Print the first n even positive integers.

 

for (i = 1; i <= n; i++)

  printf("%d ", 2 * i);

 

Java implementation

 

import java.util.*;

 

class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    int n = con.nextInt();

    for (int  i = 1; i <= n; i++)

      System.out.print(2*i + " ");

    System.out.println();

    con.close();

  }

}

 

Python implementation

Read the input value of n.

 

n = int(input())

 

Print the first n even positive integers.

 

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

  print(2*i, end = " ")

print()