53.1k views
1 vote
Declare an 8-element Y array of integer type. Read data from the keyboard into the table.

a. Calculate the sum of elements greater than zero.
b. Calculate the arithmetic mean of elements less than zero

write it in c++

User Adejoke
by
7.9k points

1 Answer

2 votes

Answer:

In C++, you can declare an 8-element integer array Y as follows:

int Y[8];

To read data from the keyboard into the array, you can use a for loop and the cin function:

for (int i = 0; i < 8; i++) {

for (int i = 0; i < 8; i++) { cin >> Y[i];

for (int i = 0; i < 8; i++) { cin >> Y[i];}

To calculate the sum of elements greater than zero, you can use another for loop to iterate through the array and add the values greater than zero to a variable:

int sum = 0;

int sum = 0;for (int i = 0; i < 8; i++) {

int sum = 0;for (int i = 0; i < 8; i++) { if (Y[i] > 0) {

int sum = 0;for (int i = 0; i < 8; i++) { if (Y[i] > 0) { sum += Y[i];

int sum = 0;for (int i = 0; i < 8; i++) { if (Y[i] > 0) { sum += Y[i]; }

int sum = 0;for (int i = 0; i < 8; i++) { if (Y[i] > 0) { sum += Y[i]; }}

To calculate the arithmetic mean of elements less than zero, you can use another for loop to iterate through the array and add the values less than zero to a variable, and divide the total by the number of elements.

int count = 0;

int count = 0;int sum = 0;

int count = 0;int sum = 0;for (int i = 0; i < 8; i++) {

int count = 0;int sum = 0;for (int i = 0; i < 8; i++) { if (Y[i] < 0) {

int count = 0;int sum = 0;for (int i = 0; i < 8; i++) { if (Y[i] < 0) { sum += Y[i];

int count = 0;int sum = 0;for (int i = 0; i < 8; i++) { if (Y[i] < 0) { sum += Y[i]; count++;

int count = 0;int sum = 0;for (int i = 0; i < 8; i++) { if (Y[i] < 0) { sum += Y[i]; count++; }

int count = 0;int sum = 0;for (int i = 0; i < 8; i++) { if (Y[i] < 0) { sum += Y[i]; count++; }}

int count = 0;int sum = 0;for (int i = 0; i < 8; i++) { if (Y[i] < 0) { sum += Y[i]; count++; }}double mean = sum / count;

It's important to note that you should make sure that the count variable doesn't equal zero, otherwise you will divide by zero which will result in an error.

User Barney Chambers
by
8.5k points