Score analysis (C++)

Description of the problem
Xiaolan organized an exam for the students, and the total score is scored. Each student's score is a whole number.

Please calculate the highest score, lowest score and average score for this exam.

Input format
The first line of input contains an integer that represents the number of people to take the exam.

In the next row, each row contains an integer to indicate the score of a student.

Output format
Three lines are output.

The first line contains an integer that represents the highest score.

The second line contains an integer that represents the lowest score.

The third line contains a real number, rounded to the nearest two decimal places, indicating an average score.

Sample input
7
80
92
56
74
88
99
10

Sample output
99
10
71.29

Insert picture description here

#include<iostream>
using namespace std;
const int N = 1e4+10;
int main()
{
    
    
	int n ,num[N] ,min ,max;
	double sum = 0;
	cin>>n;
	for(int i = 0;i<n;i++){
    
    
		cin>>num[i];
	}
	min = max = num[0];
	for(int i = 0;i<n;i++){
    
    
		if(min>num[i]){
    
    
			min = num[i];
		}
		if(max<num[i]){
    
    
			max = num[i];
		}
		sum += num[i];
	}
	cout<<max<<'\n'<<min<<endl;
	printf("%.2f\n",sum/n);
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_51430516/article/details/115270713