我想按从大到小的降序排列k_p
和10个学生的s_s_s
,然后打印出来,但我不知道怎么做……
#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;
}
我尝试过这样的东西,但我不知道如何将它放入代码中
{
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
}
}
}
https://stackoverflow.com/questions/52508024
复制相似问题