Consider the followingc int main() cons int SIZE - 20 int values [SIZE0, 23, 34,
ID: 3738802 • Letter: C
Question
Consider the followingc int main() cons int SIZE - 20 int values [SIZE0, 23, 34, 7, 110, 42, -350, 424, 25, 99, 10, 05, 50, -5, 1, 200, -350, 437, 25, 147 // your code goes here Write a complete program to display the values from each of the following four steps. All displays must be done in main. Use separate functions for each step below, passing the array to each function. 1.1) Provide the sum of the numbers in this array function must return an int. 1.2) Provide the average of the positive numbers in this array - function must return a 1.3) 1.4) double Provide the lowest number in the array - function must return an int. Provide the highest number in the array - function must return an int.Explanation / Answer
#include<iostream>
#include<vector>
using namespace std;
int sum(vector<int> a, int n) {
int t =0;
for(int i=0;i<n;i++){
t+=a[i];
}
return t;
}
double average(vector<int> a, int n){
int t = sum(a,n);
return t/(double)n;
}
int minimum(vector<int> a, int n){
int min = a[0];
for(int i=1;i<n;i++){
if(min > a[i])
min = a[i];
}
return min;
}
int maximum(vector<int> a, int n){
int max = a[0];
for(int i=1;i<n;i++){
if(max < a[i])
max = a[i];
}
return max;
}
int main() {
const int SIZE = 20;
vector<int> values;
values.push_back(0);
values.push_back(23);
values.push_back(34);
values.push_back(-7);
values.push_back(110);
values.push_back(42);
values.push_back(-350);
values.push_back(424);
values.push_back(25);
values.push_back(99);
values.push_back(10);
values.push_back(05);
values.push_back(-5);
values.push_back(1);
values.push_back(2);
values.push_back(200);
values.push_back(-350);
values.push_back(437);
values.push_back(25);
values.push_back(147);
cout<<"Sum: "<<sum(values, SIZE)<<endl;
cout<<"Average: "<<average(values, SIZE)<<endl;
cout<<"Min: "<<minimum(values, SIZE)<<endl;
cout<<"Max: "<<maximum(values, SIZE)<<endl;
return 0;
}
Output: