In this program, you should define an array of 10 elements in your data segment with these values: ? = {11, 12,−10, 13, 9, 12, 14, 15,−20, 0} a. Write a function which finds the maximum value of this array. b. Write another function which calculates the summation of this array. c. Call these functions in your main program, and print the outputs of these functions to the user i. “The maximum is 15” ii. “The summation is 56” d. What is the address that has been used by the simulator for this array?
The given problem can be implemented in C++ in following way :
#include <iostream>
#include<climits>
using namespace std;
//part A
int maxfun(int A[], int n)
{
int m = INT_MIN;
for(int i = 0; i < n; i++)
{
if( m <= A[i])
m = A[i];
}
return m;
}
//part B
int sumfun(int A[], int n)
{
int s = 0;
for(int i = 0; i < n; i++)
s += A[i];
return s;
}
int main()
{
int A[] = {11, 12, -10, 13, 9, 12, 14, 15, -20, 0};
// part C
int max = maxfun(A, 10);
int sum = sumfun(A, 10);
cout<<"The max is "<<max<<" and the sum is "<<sum;
return 0;
}
Please upvote if you find the answer helepful.
Get Answers For Free
Most questions answered within 1 hours.