C++ 陈列 问题

来源:百度知道 编辑:UC知道 时间:2024/05/29 16:47:33
学生号 成绩 差平均点
1234 64 -2
1237 67 1
1237 67 1
平均点 66

我是新手 请问大家怎么做
用 C++
输入 学号 成绩 一共 10人

#include <iostream>
using namespace std; // 这两句相当于#include <iostream.h>
#define NUM 10
struct student
{
int number,score;
};
void main()
{
struct student studs[NUM];
int i, ap=0;
cout <<"请输入"<<NUM<<"个学生信息(学号 成绩):"<<endl;
for(i=0;i<NUM;i++)
{
cin>>studs[i].number>>studs[i].score;
ap+=studs[i].score;
}
ap/=NUM;

cout<<"学号\t成绩\t差平均点"<<endl;
for(i=0;i<NUM;i++)
{
cout<<studs[i].number<<'\t'<<studs[i].score<<'\t'<<studs[i].score-ap<<endl;
}
}

先计算平局点,再计算差平均点。