3. For a given array, please computing the product and sum of all the elements i
ID: 3593639 • Letter: 3
Question
3. For a given array, please computing the product and sum of all the elements in the array and print the results. For example, for the array list [34] (1,2,3,4), the product-1*2*3*4.24 and sum= 1+2+3+4-10. #include #include using namespace std; const int ARRAY SIZE-4 void product sum(int myList,int arraySize, int& myProduct, int& mySum) int main)f int list [ARRAY_SIZE]={1,2,3,4}; //your code here cin.get O void product sum (int myListl, int arraysize, int& myProduct, int& mySum) /I you code goes hereExplanation / Answer
#include<iostream>
#include<iomanip>
using namespace std;
const int ARRAY_SIZE = 4;
void product_sum(int myList[], int arraySize, int &myProduct, int &mySum);
int main(){
int list[ARRAY_SIZE] = {1,2,3,4};
int i = 0;
int sum =0;
int product = 1;
for( int i = 0; i < ARRAY_SIZE ; i++){
sum = sum + list[i];
product = product * list[i];
}
product_sum(list,ARRAY_SIZE,product,sum);
cin.get();
return 0;
}
void product_sum(int myList[], int arraySize, int &myProduct, int &mySum){
int i = 0;
cout<<"array:";
for( int i =0; i < ARRAY_SIZE ; i++){
cout<<myList[i]<<" ";
}
cout<<" product:"<<myProduct;
cout<<" sum:"<<mySum;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.