PROGRAM STATEMENT:
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:
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.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:
#includeint main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int arr[n]; for(int i=0;i
#includeusing namespace std; int main() { int t;cin>>t; while(t--) { int n;cin>>n; int arr[n]; for(int i=0;i >arr[i]; if(i%2==0) { cout<
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(); while(t!=0) { 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.