#include <stdio.h>
#include <time.h>
#include <stdlib.h>
using namespace std;
struct student
{
int shuxue;
int yuwen;
int yingyu;
};
int main(int, char **)
{
srand(time(0));
const int XUESHENG_RENSHU = 10;
student stu[XUESHENG_RENSHU];
int sum_shuxue = 0;
int sum_yuwen = 0;
int sum_yingyu = 0;
// 我先随机写入数据
for (size_t index = 0; index < XUESHENG_RENSHU; ++index) {
stu[index].shuxue = rand() % 100;
stu[index].yuwen = rand() % 100;
stu[index].yingyu = rand() % 100;
printf("学生%d : 数学[%d], 语文[%d], 英语[%d]\n",
index, stu[index].shuxue, stu[index].yuwen, stu[index].yingyu);
}
//简单的求和
for (size_t index = 0; index < XUESHENG_RENSHU; ++index) {
sum_shuxue += stu[index].shuxue;
sum_yuwen += stu[index].yuwen;
sum_yingyu += stu[index].yingyu;
}
printf("===================================\n");
printf(" 总分 \n");
printf("数学\t%d\n", sum_shuxue);
printf("语文\t%d\n", sum_yuwen);
printf("英语\t%d\n", sum_yingyu);
return 0;
}
给你个我我自己写的吧,我也没懂你要问什么,
这个时C++代码,和C的略有不同,应该能看懂。
溜了~溜了~溜了~ |