《高级语言程序设计》实验报告实验序号:8 实验项目名称:结构体
1. #include<stdio.h>
struct student
{
int num;
char name[20];
char classname[20];
float score[3];
核糖体蛋白float aver_score;
}stu[5];
void input()
{
上海冶金矿山机械厂
int i;
for(i=1;i<6;i++)
{ printf("第%d个同学",i);
printf("请输入学号名字班级三门课程成绩:\n"); scanf("%d %s %s %f %f %f",&stu[i].num,stu[i].name,stu[i].classname,&stu[i].score[1],&stu [i].score[2],&stu[i].score[3]);
}
};
void averagescore()
{
int i;
for(i=1;i<=5;i++)
stu[i].aver_score=((stu[i].score[1]+stu[i].score[2]+stu[i].score[3])/3);
printf("平均成绩:");
for(i=1;i<6;i++)
printf("第%d个同学的平均成绩%f:\n",i,stu[i].aver_score);
printf("\n");
};
void max()
{
int i,k=0;
float temp=stu[1].aver_score;
浙江林学院学报
for(i=2;i<=5;i++)
if(stu[i].aver_score>temp) {temp=stu[i] .aver_score;k=i;};
printf("成绩最好的同学:\n");
printf("%d %s %s %4.2f %4.2f %4.2f %4.2f\n",风胸
stu[k].num,stu[k].name,stu[k].classname,stu[k].score[1],stu[k].score[2],stu[k].score[3],stu[k].aver _score);设备管理系统
};
void main()
{
input();
averagescore();
max();
}
2.#include <stdio.h>
struct worker
{
char name[20];
int workyear;
float salary;
}work[5];
void input()
{
int i;
for(i=1;i<=5;i++)
{
printf("第%d个工人:",i);
printf("请输入名字工作年限工资总额:\n");
scanf("%s %d %f",&work[i].name,&work[i].workyear,&work[i].salary);