首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在C中对结构元素进行排序并将其打印出来

在C中对结构元素进行排序并将其打印出来
EN

Stack Overflow用户
提问于 2018-09-26 07:46:10
回答 1查看 63关注 0票数 0

我想按从大到小的降序排列k_p和10个学生的s_s_s,然后打印出来,但我不知道怎么做……

代码语言:javascript
运行
复制
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct student {
    float k_p;
    char i_p[30];
    int s_s_s;
};

int main() {
    struct student S[10];
    int i;
    for(i=0;i<10;i++) {
        printf("Student broj %d\n", i+1);
        printf("Koeficijent place: \t"); scanf("%d", &S[i].k_p);
        printf("Ime i prezime: \t"); scanf("%s", &S[i].i_p);
        printf("Stupanj strucne spreme: \t"); scanf("%f",&S[i].s_s_s);
        system("cls");
    }
    return 0;
}

我尝试过这样的东西,但我不知道如何将它放入代码中

代码语言:javascript
运行
复制
{
    for (int j = 0; j < n; j++) {     //Loop for comparing other values
        if (a[j] < a[i]) {            //Comparing other array elements
            int tmp = a[i];           //Using temporary variable for storing last value
            a[i] = a[j];              //replacing value
            a[j] = tmp;               //storing last value
        }
    }
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52508024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档