zoukankan      html  css  js  c++  java
  • c语言学习之结构篇代码演示样例-输入n个同学的姓名,数学英语成绩,依照平均分从低到高排序并输出

    #include<stdio.h>
    void main(){

    const int count = 5;//定义数量
    struct student{
    char name[80];
    float math,eng;
    float aver;

    }stu[count],temp;

    //输入

    for (int i = 0; i < count; i++){
    scanf("%s%f%f", stu[i].name, &stu[i].math, &stu[i].eng);
    }
    //将平均值放入进去
    for (int i = 0; i < count; i++){
    stu[i].aver = (stu[i].math + stu[i].eng )/ 2;
    }
    /*求平均分最高的同学姓名和平均分
    int sub = 0;
    for (int i = 1; i < 5; i++)
    if (stu[i].aver>stu[sub].aver)sub = i;
    printf("%s%f ", stu[sub].name, stu[sub].aver);*/
    /*依照平均分从低到高排序*/
    for (int i = 0; i < count - 1; i++)
    for (int j = 0; j < count - 1 - i; j++)
    if (stu[j].aver>stu[j + 1].aver){
    temp = stu[j];
    stu[j] = stu[j + 1];
    stu[j + 1] = temp;
    }
    //输出
    for (int i = 0; i < count; i++){
    printf("%s %f %f %f ", stu[i].name, stu[i].math, stu[i].eng, stu[i].aver);
    }
    }
  • 相关阅读:
    (转)C# DES
    (转)adb shell am 的用法
    (转)C# 解析 json
    (转)C#执行exe程序
    (转) C# textbox 限制输入问题
    (转)C# SSL-X509使用
    事务管理
    spring数据源
    2.spring 学习
    sonarqube 代码检查
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/3817110.html
Copyright © 2011-2022 走看看