Answer to Question #348555 in C++ for Hasnat

Question #348555



Create an array of size ten, get input from user, show odd index sum and even index sum, show array element by element




1
Expert's answer
2022-06-08T14:27:05-0400
#include <iostream>

using namespace std;

int main()
{
	int arr[10];
	int oddsum = 0, evensum = 0;
	cout << "Please, enter 10 values for array: ";
	for (int i = 0; i < 10; i++)
	{
		cin >> arr[i];
	}
	for (int i = 1; i < 10; i+=2)
	{
		oddsum+=arr[i];
	}
	cout << "Odd index summ: "<<oddsum;
	for (int i = 0; i < 10; i += 2)
	{
		evensum+=arr[i];
	}
	cout << "\nEven index summ: " << evensum << endl;
	cout << "All elements: ";
	for (int i = 0; i < 10; i++)
	{
		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