结构体

本文介绍了一个使用C语言实现的学生信息管理系统,该系统能够输入学生的姓名、学号及三门课程的成绩,并计算平均分。此外,还实现了寻找最高平均分的学生并打印其详细信息的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <stdio.h>


struct Student
{
    char name[20];
    int num;
    float score[3];
    float aver;
};


void input(struct Student stu[]);
struct Student max(struct Student stu[]);
void print(struct Student stu_m);


int main()
{
    struct Student stu[3];
    struct Student *p;
    p = stu;
 
    input(p);
    max(p);
    print(max(p));
    return 0;
}


void input(struct Student stu[])
{
    int i;
    printf("enter: name num score[3], 3 stu\n");
    for(i = 0; i < 3; i++)
    {
int j;
scanf("%s %d", stu[i].name, &stu[i].num);
for(j = 0; j < 3; j++)
{    
   scanf("%f", &stu[i].score[j]);
        
}
float temp = 0.0;
for(j = 0; j < 3; j++)
{
   temp += stu[i].score[j];
}
stu[i].aver = temp / 3.0;
    }
}


struct Student max(struct Student stu[])
{
    int i, m = 0;
    for(i = 0; i < 3; i++)
    {
        if(stu[i].aver > stu[m].aver)
{
   m = i;
}
    }
    return(stu[m]);
}


void print(struct Student stu_m)
{
    printf("max: %s %d %.2f %.2f %.2f %.2f\n", stu_m.name, stu_m.num, stu_m.score[0], stu_m.score[1], stu_m.score[2], stu_m.aver);//企图用stu_m.score打印全部数组值;与stu_m.name数组不一样的是字符串打印传的是地址,其中字符串名表示第一个字符的地址但%s有打印第一个字符后,地址自加一功能,因此能打印全部字符串
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值