problem no 35:(array problem):alternate array printing.

QUESTION: 


You are given an array A of size N. You need to print elements of A in alternate order (starting from index 0).

Example 1:

Input:
N = 4
A[] = {1, 2, 3, 4}
‹Output:
1 3

Example 2:

Input:
N = 5
A[] = {1, 2, 3, 4, 5}
‹Output:
1 3 5

 

ANSWER:

 

void print(int ar[], int n)
{
   
    for(int i=0;i<n;i++)
    {
        if(i%2==0)
        {
            cout<<ar[i]<<" ";
        }
    }
   
   
}

Comments

Popular posts from this blog

problem 3: given two integers N and M. The problem is to find the number closest to N and divisible by M. If there are more than one such number, then output the one having maximum absolute value.

problem no 7:Given two numbers A and B, find Kth digit from right of AB.

Problem no 16: count the number of squares below N.