铺垫一个 数据类型

#include<stdio.h>
struct student
{
    int num;
    char name[20];
    float score;
};
int main()
{
    int i,j;
    struct student stu[5],temp;
    for(i=0;i<5;i++)
    {
        scanf("%d%s%f",&stu[i].num,&stu[i].name,&stu[i].score);
    }
    for(i=0;i<4;i++)
    {
        for(j=0;j<4-i;j++)
        {
            if(stu[j].score>stu[j+1].score)
            {
                temp=stu[j];
                stu[j]=stu[j+1];
                stu[j+1]=temp;
            }
        }
    }
    for(i=0;i<5;i++)
    {
        printf("%10d%10s%10.2f
",stu[i].num,stu[i].name,stu[i].score);
    }
    return 0;
}

这个  挺简单的   但是当时  不想看书   跳跃太大...看数据结构   也看不懂了.看来学习应该是 慢慢来 基础要  扎实

#include<stdio.h>
struct student
{
    int num;
    char name[20];
    float score;
};
int main()
{
    int i,j;
    struct student stu[5],temp,*p;
    for(p=stu,i=0;i<5;i++,p++)
    {
        scanf("%d%s%f",&p->num,&p->name,&p->score);
    }
    for(i=0;i<4;i++)
    {
        for(j=0;j<4-i;j++)
        {
            if(stu[j].score>stu[j+1].score)
            {
                temp=stu[j];
                stu[j]=stu[j+1];
                stu[j+1]=temp;
            }
        }
    }
    for(p=stu,i=0;i<5;i++,p++)
    {
        printf("%10d%10s%10.2f
",p->num,p->name,p->score);
    }
    return 0;
}

测试数据:

10101 zhang 78

10103 wang 98.5

10106 li 86

10108 ling 78.5

10110 sun 100

原文地址:https://www.cnblogs.com/A-FM/p/5043219.html