C语言学生成绩排名系统

实验作业:用C语言设计函数输出对n个学生三门课程成绩总分排名。

一个小小的实验作业,感觉挺有意思的,这是我个人设计的代码,代码也不算复杂,主要就是涉及到链表的使用,很简单,代码如下:

#include<stdio.h>
#include<stdlib.h>
struct node
{
    char name[50];
    char eng[20];
    int math1;
    int math2;
    int math3;
    int sum=0;
    int ran;
    struct node *next;
}*head,*q,*t;


void my_sort(struct node *head)//学生成绩排序
{
    struct node *cur, *tail,*tt;
    cur=head;
    tail=NULL;
    if(cur==NULL||cur->next==NULL)return;
    while(cur!=tail)
    {
        while(cur->next!=tail)
        {
            if(cur->sum>cur->next->sum)
            {
                cur->ran=cur->ran-1;
            }
            cur=cur->next;
        }
        if(cur->next==NULL)tt=cur;
        tail=cur;
        cur=head;
    }
    while(cur!=tt)
    {
        if(tt->sum>cur->sum)tt->ran--;
        cur=cur->next;
    }
}

void input(int n)//输入信息
{
    struct node *p;
    p=(struct node *)malloc(sizeof(struct node));
    p->next= NULL;
    scanf("%s%s%d%d%d",p->name,p->eng,&p->math1,&p->math2,&p->math3);
    p->sum=p->math1+p->math2+p->math3;
    p->ran=n;
    if(head==NULL)head=p;
    else q->next=p;
    q=p;
}

void output()//输出信息
{
    t=head;
    while(t!=NULL)
    {
        printf("姓名:%s\n学号:%s\n总成绩:%d\n排名:%d\n",t->name,t->eng,t->sum,t->ran);
        t=t->next;
    }
}

int main()
{
    head=NULL;
    printf("请输入有几名同学:\n");
    int n;
    scanf("%d",&n);
    printf("请分别输入姓名,学号,各科成绩:\n");
    for(int i=0;i<n;i++)
    {
        input(n);
    }
    my_sort(head);
    printf("学生成绩及排名如下:\n");
    output();

}

  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值