Create an array of size ten; get input from user, show only odd index values in one go and then only even index values in one go.
#include <iostream>
using namespace std;
int main()
{
int arr[10];
cout << "Please, enter 10 values for array: ";
for (int i = 0; i < 10; i++)
{
cin >> arr[i];
}
cout << "Odd index values: ";
for (int i = 1; i < 10; i+=2)
{
cout<< arr[i]<<" ";
}
cout << "\nEven index values: ";
for (int i = 0; i < 10; i += 2)
{
cout << arr[i] << " ";
}
}
Comments
Leave a comment