Answer to Question #348551 in C++ for Hasnat

Question #348551

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.

1
Expert's answer
2022-06-06T14:58:40-0400
#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] << " ";
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS