Output the number of scores, the average, the sorted list, the highest, and the lowest. Use the following data to enter: 10
100 90 89 98 50 66 89 80 92 99
Code Screenshot :
Executable Code:
#include <iostream>
using namespace std;
void average(int arr[],int n){
double avg ,sum = 0;
for (int i = 0; i < n; i++)
{
sum+=arr[i];
}
cout<<"\nAverage: "<<sum/n;
}
void highest(int arr[],int n){
int max = arr[0];
for (int i = 0; i < n; i++)
{
if (max < arr[i])
max =
arr[i];
}
cout<<"\nHighest Marks: "<<max;
}
void lowest(int arr[],int n){
int i;
int min = arr[0];
for (i = 0; i < n; i++)
{
if (min > arr[i])
min =
arr[i];
}
cout<<"\nLowest Marks: "<<min;
}
void sort(int arr[],int n){
int i,temp,j;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]<arr[j])
{
temp =arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
cout<<"\nMarks after sorting
:"<<endl;
for(i=0;i<n;i++)
cout<<arr[i]<<"\n";
cout<<endl;
}
int main()
{
int marks[150],size;
cout<<"Please enter the number of test scores:
";
cin>>size;
for(int i=0 ;i<size; i++){
cin>>marks[i];
}
highest(marks,size);
lowest(marks,size);
sort(marks,size);
average(marks,size);
return 0;
}
Sample Output :
Please comment
below if you have any queries.
Please do give a thumbs up if you liked the answer thanks
:)
Get Answers For Free
Most questions answered within 1 hours.