# Print Alternate Elements of an Array

Print Alternate Elements of an Array” is again elementary problem of array data structure. Here, we are given an array of size ‘n’ and our task is to print the alternate element of an array. Alternate elements defines, we are not supposed to print two subsequent elements.

Example:

```INPUT:
Arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
OUTPUT:
1 ,3, 5, 7, 9
OR
2, 4, 6, 8, 10```

The steps required to print the alternate elements of the array are as follows:

• Scan the size of the array from user.
• Scan the array elements from the user.
• To print alternate element of the array, we have two choices:
• Start from array element with index 0 (arr) and then iterate with index + 2. So, here all the even index elements will be printed.
• Start from array element with index 1(arr) and then iterate with index +2. So, here all the odd index elements will be printed.

C++ Program to print the alternate elements of the array is as follows:

```/* C++ Program to print alternate elements of the array */
#include<bits/stdc++.h>
using namespace std;
int main()
{
/* Scan size of array */
int n;
cout<<"Enter the size of the array:";
cin>>n;

/*Scan array elements */
int arr[n];
cout<<"\nEnter the array elements:";
for(int i = 0; i < n; i++)
{
cin>>arr[i];
}

/*print alternate elements */
cout<<"\nThe alternate elements of the array are:\n";
for(int i = 0; i < n; i = i+2)
{
cout<<arr[i]<<" ";
}
}

```
```OUTPUT:
Enter the size of the array: 9
Enter the array elements: 11 22 33 44 55 66 77 88 99
The alternate elements of the array are:
11 33 55 77 99
Time Complexity:
O(n), where n is the size of the array```

Related Posts: