In a competition event, five (5) trials are allowed per participant. A scores is awarded and recorded
for each trial. At the end of the trials, simple average of scores is calculated for the final score of the
participant.
If the event has 100 participants:
(1) Write a function to input data for all participants.
(2) Write a function to display the top three (3) participants and their final scores.
#include <bits/stdc++.h>
using namespace std;
struct participant{
int scores[5];
};
void inputData(participant p[],int n){
for(int i=0;i<n;i++){
cout<<"\nEnter scores of participant "<<(i+1)<<":";
for(int j=0;j<5;j++){
cin>>p[i].scores[j];
}
}
}
void getTopThree(int arr[],int n){
sort(arr, arr + n);
cout<<"\nThe top three are:\n";
cout<<"\n1. "<<arr[n-1];
cout<<"\n2. "<<arr[n-2];
cout<<"\n3. "<<arr[n-3];
}
int main()
{
int n=100;
participant p[n];
inputData(p,n);
int avg[n];
for(int i=0;i<n;i++){
int sum=0;
for(int j=0;j<5;j++){
sum+=p[i].scores[j];
}
int a=sum/5;
avg[i]=a;
}
getTopThree(avg,n);
return 0;
}
Comments
Leave a comment