Enter the five student achievement in a course, find the average score, the highest score of the students and the corresponding index in the array.

Enter the five student achievement in a course, find the average score, the highest score of the students and the corresponding index in the array.

#include<iostream>
using namespace std;
int main()
{
	int math[3],max;
	int n=0;
	cout<<"请输入成绩:"<<endl;
	for(int i=1;i<=3;i++)
	{
		cin>>math[i];
	}
	max=math[0];
	for(int j=1;j<=3;j++)
	{
		if(max<math[j])
		{
			max=math[j];
			n++;
		}
	}
	cout<<"最高分为:"<<max<<",是第"<<n<<"个学生."<<endl;
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_43803070/article/details/92680024