Write a pseudocode algorithm whose purpose is to find the maximum, minimum and s
ID: 664615 • Letter: W
Question
Write a pseudocode algorithm whose purpose is to find the maximum, minimum and sum for a collection of numbers. To practice the concepts of local scope, references, and functions, your pseudocode will have the following:
o A main function that asks the user for ten marks
o A function named findMinandMaxSum that finds the lowest and highest of all the marks, and the sum of all elements and returns them through reference parameters. This function cannot display or print anything!
o Your main function call findMinandMaxSum to obtain the three values, and then print them.
You must write complete algorithm including the algorithm header and algorithm body
Explanation / Answer
working c++ code
#include<iostream>
typedef struct check
{
int max;
int min;
int sum;
} check;
check findMinandMaxSum(int arr[])
{
check mycheck;
int i,mi,ma,su;
mi=0;
ma=0;
su=0;
for (i=0;i<10;i++)
{
if (i==0)
{
mi=arr[i];
ma=arr[i];
}
if (arr[i]<mi)
mi=arr[i];
if (arr[i]>ma)
ma=arr[i];
su=su+arr[i];
}
mycheck.max = ma;
mycheck.min = mi;
mycheck.sum = su;
return mycheck;
}
int main()
{
int arr[10];
int i;
for (i=0;i<10;i++)
{
cin>>arr[i];
}
check maincheck;
maincheck = findMinandMaxSum(arr);
cout<<"max number is"<<endl;
cout<<maincheck.max<<endl;
cout<<"min number is"<<endl;
cout<<maincheck.min<<endl;
cout<<"Sum is"<<endl;
cout<<maincheck.sum<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.