First evens#8916

First evens (Editorial)

Print the first even positive integers in ascending order.

Algorithm implementation

Read the input value of .

scanf("%d", &n);

Print the first 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 = int(input())

Print the first even positive integers.

for i in range(1,n+1):
  print(2*i, end = " ")
print()