Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help please: Write a code fragment in C++ using ONE for-loop to calculate t

ID: 3541043 • Letter: N

Question

need help please:

Write a code fragment in C++ using ONE for-loop to calculate the sum and product of the elements of a floating point array. The array is declared as shown below. Include any other declarations and initialization statements necessary to perform the operation.  Display the sum and product results after the for-loop using cout.

const int MAX = 15;
float values[MAX] = {98.0, 75.0, 66.5, 78.5, 83.5, 89.0,
   94.0, 43.0, 99.0, 88.0, 42.5, 72.0, 59.5, 77.0, 63.5}; (Points : 20)       

Explanation / Answer

please rate - thanks


any questions ask-I will make changes



#include<iostream>
using namespace std;
int main()
{const int MAX = 15;
float values[MAX] = {98.0, 75.0, 66.5, 78.5, 83.5, 89.0,
94.0, 43.0, 99.0, 88.0, 42.5, 72.0, 59.5, 77.0, 63.5};
float sum=0;
float product=1;
int i;
for(i=0;i<MAX;i++)
   {sum+=values[i];
   product*=values[i];
   }
cout<<"sum = "<<sum<<" product = "<<product<<endl;
system("pause");
}