Create an array of size ten, get input from user, show odd index sum and even index sum, show array element by element
#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]<<" ";
}
}
Comments
Leave a comment