• c语言中结构体数组


    c语言中结构体数组。

    1、

    #include <stdio.h>
    #include <string.h>
    
    #define NUMBER 5
    #define NAME_LEN 64
    
    typedef struct{
        char name[NAME_LEN];
        int height;
        float weight;
        long schols;
    } Student;
    
    void swap_str(Student *x, Student *y)
    {
        Student temp = *x;
        *x = *y;
        *y = temp;
    }
    
    void sort_height(Student a[], int n)
    {
        int i, j;
        for(i = 0; i < n - 1; i++)
        {
            for(j = n - 1; j > i; j--)
            {
                if(a[j - 1].height > a[j].height)
                {
                    swap_str(&a[j - 1], &a[j]);
                }
            }
        }
    }
    
    int main(void)
    {
        int i;
        Student std[] = {
        {"Sato", 178, 61.2, 80000},
        {"Sanaka", 175, 62.5, 73000},
        {"Takao", 173, 86.2, 0},
        {"Mike", 165, 72.3, 70000},
        {"Masaki", 179, 77.5, 70000}
        };
        
        for(i = 0; i < NUMBER; i++)
            printf("%-8s %7d%7.2f%7ld
    ", std[i].name,std[i].height,std[i].weight,std[i].schols);
            
        sort_height(std, NUMBER);
        puts("
    ===========================");
        for(i = 0; i < NUMBER; i++)
            printf("%-8s %7d%7.2f%7ld
    ", std[i].name, std[i].height, std[i].weight, std[i].schols); 
        
        return 0;
    }

  • 相关阅读:
    2016/3/10 Java 错题
    2016/3/9 Java 错题集
    Java Socket 编程实验总结
    CSU 1290
    CSU 1307
    CSU 1060
    Problem B SPOJ DCEPC11I
    activemq 学习系列(二) 常用配置
    activemq 学习系列(一) 详细入门使用
    MySql 用户创建与授权
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14849042.html
Copyright © 2020-2023  润新知