Algorithm Analysis
Let's read the input sequence of numbers into an array. Next, using a loop, we will print all the array elements with even indices.
Algorithm Implementation
Declare the working array.
int m[101];
Read the number of input numbers .
scanf("%d", &n);
Read the input array.
for (i = 0; i < n; i++) scanf("%d", &m[i]);
Print the array elements with even indices.
for (i = 0; i < n; i++) if (i % 2 == 0) printf("%d ", m[i]);
Java Implementation
import java.util.*; public class Main { public static void main(String[] args) { Scanner con = new Scanner(System.in); int n = con.nextInt(); int m[] = new int[n]; for (int i = 0; i < n; i++) m[i] = con.nextInt(); for (int i = 0; i < n; i++) if (i % 2 == 0) System.out.print(m[i] + " "); con.close(); } }
Python Implementation
n = int(input()) lst = list(map(int, input().split())) for i in range(n): if i % 2 == 0: print(lst[i], end = " ")