Write a program to print roll no and names of 10 students using array


Given N seats, where English paper students are evenly placed (0,2,4,...) and Hindi paper students are oddly placed (1,3,5,...). Print the roll number of English paper students.

See original problem statement here

For Example :

N = 5 
Arr[] = [1, 2, 3, 4, 5]

Output: 1 3 5

Explanation: Students with roll number 1 3 5 are placed on even indexes i.e. 0 2 4.

How to print roll no and names of students using array:

  1. Keep traversing the array and print the elements that are placed on even indices as the English paper students are sitting on roll numbers like 0, 2, 4 etc.

  2. If the current index is a multiple of 2, then print it else move ahead.

Program to print roll no and names of 10 students using array:


int main()
  int t;
    int n;
    int arr[n];
    for(int i=0;i


using namespace std;

int main()
  int t;cin>>t;
    int n;cin>>n;
    int arr[n];
    for(int i=0;i>arr[i];


import java.util.*;
import java.io.*;

public class Main {
  public static void main(String args[]) throws IOException {
    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
      int n = sc.nextInt();
      int arr[] = new int[n];
      for(int i=0;i

n = int(input())
arr = list(map(int,input().split()))
for i in range(n):
	if i%2==0:
		print(arr[i], end = " ")

Space Complexity: O(1)

[forminator_quiz id="561"]
This article tried to discuss the concept of Basic Mathematics. Hope this blog helps you understand the concept. To practice more problems you can check out MYCODE | Competitive Programming.

Leave a Reply

Your email address will not be published. Required fields are marked *