Please help!!! Write a C/C++ program that does the followi’ng: •declare an array
ID: 673754 • Letter: P
Question
Please help!!!
Write a C/C++ program that does the followi’ng:
•declare an array of integers (size is your choice)--your program should work with any array size
•call an assembly function to compute the average of all elements in the array (pass the array and the size of the array)
•call an assembly function to compute the largest (max) of all elements in the array (pass the array and the size of the array)
•call an assembly function to compute the smallest (min) of all elements in the array (pass the array and the size of the array)
•display the average, min, and max
three assembly files for the three functions (average-40 points, largest-30points, smallest-30 points)
Explanation / Answer
Please note Here I am giving normal function call used in c/c++. I don't understand the meaning Assembly function here. So you can comment on my answer with more information and i will give you exact answer if I failed to provide now.
#include <iostream>
using namespace std;
int main()
{
int array[10],i;
//Declaration of functions
double average(int[],int);
int maximum(int[],int);
int minimum(int[],int);
cout<<"Enter 10 elements for the array"<<endl;
for(i=0;i<10;i++)
cin>>array[i];
//Calling of functions
cout<<"The average is "<<average(array,10)<<endl;
cout<<"The maximum element is "<<maximum(array,10)<<endl;
cout<<"The minimum is "<<minimum(array,10)<<endl;
return 0;
}
double average(int array[],int size)
{
int i,sum=0;
for(i=0;i<size;i++)
{
sum=sum+array[i];
}
double avg=sum/10.0; // please note here I am dividing the sum with 10.0 not with 10 because if i use 10 then It is integer/ integer case and output will come integer only. So it will truncate digits after decimal. To retain decimal I used 10.0 now it becomes a case of integer/float.
return avg;
}
int maximum(int array[],int size)
{
int max=array[0];
int i;
for(i=0;i<size;i++)
{
if(max<=array[i])
{
max=array[i];
}
}
return max;
}
int minimum(int array[],int size)
{
int i;
int min=array[i];
for(i=0;i<size;i++)
{
if(array[i]<=min)
{
min=array[i];
}
}
return min;
}