谢谢您的回答 可是还有一道跟它相关的题#include #include struct student{\x05int id;\x05int score;};void sort(struct student* students,int n){/*Sort the n students based on their score*/ /* Remember,each student must be matched with th

来源:学生作业帮助网 编辑:作业帮 时间:2024/10/02 14:53:44
谢谢您的回答 可是还有一道跟它相关的题#include #include struct student{\x05int id;\x05int score;};void sort(struct student* students,int n){/*Sort the n students based on their score*/ /* Remember,each student must be matched with th
xVKo1>?,FI8mR H98NhPH<8@8/k_%Mi"曙GG_w٧w/&;?{{G?޿難'_O^~zǻW1 $D p@?)up[PAq8e)x7:q]=]Q(QX bwk  R'\.1@Z>b m]\4|m>E: }VHII6yGcW=CZLig˕ 1A'$1iUq!&No TFȇ/-B9}y(0JвEjz7PH.(l(+p7J+7bʈIt[k\ќ(ap8 BTViOː1`&Z[5Q (@5 z |. #e_vsZ. o_E w:&Qhg Ȝ.eM lWig$-x i]X9Яb0D%sSR*$u ,aW<, ~jz1U7^ {_JwR/jͼN/ .sg]v:>k=%ZsX烢Rxu 3Kɜzjs޴躖l"sѹz,ot۰/HI}]91fZi+37R7= ] U;K:1=ۋf4:U\9_-DTBL>Ct7niʯv>dU}

谢谢您的回答 可是还有一道跟它相关的题#include #include struct student{\x05int id;\x05int score;};void sort(struct student* students,int n){/*Sort the n students based on their score*/ /* Remember,each student must be matched with th
谢谢您的回答 可是还有一道跟它相关的题
#include
#include
struct student{
\x05int id;
\x05int score;
};
void sort(struct student* students,int n){
/*Sort the n students based on their score*/
/* Remember,each student must be matched with their original score after sorting */
}
int main(){
/*Declare an integer n and assign it a value.*/
/*Allocate memory for n students using malloc.*/
/*Generate random IDs and scores for the n students,using rand().*/
/*Print the contents of the array of n students.*/
/*Pass this array along with n to the sort() function*/
/*Print the contents of the array of n students.*/
return 0;
}

谢谢您的回答 可是还有一道跟它相关的题#include #include struct student{\x05int id;\x05int score;};void sort(struct student* students,int n){/*Sort the n students based on their score*/ /* Remember,each student must be matched with th

#include <stdio.h>
#include <stdlib.h>
struct student{
int id;
int score;
};
void sort(struct student* number, int n){
     int i,j;
     struct student t;
     for(i=0; i<n; i++)
         for(j=i+1; j<n; j++)
             if (number[j].score>number[i].score)
             {
                 t = number[j];
                 number[j] = number[i];
                 number[i] = t;
             }
}
 
int main(){
    int n = 20;
    int i;
     
    struct student* number= (int *)malloc(n * sizeof(struct student));

    for(i=0; i<n; i++) {
        number[i].id = rand() % (n+1);
        number[i].score = rand() % 100;
    }

    for(i=0; i<n; i++) {
        printf("number[%d].id=%d\n", i, number[i].id);
        printf("number[%d].score=%d\n", i, number[i].score);
    }
 
    sort(number, n);
     
    for(i=0; i<n; i++) {
        printf("number[%d].id=%d\n", i, number[i].id);
        printf("number[%d].score=%d\n", i, number[i].score);
    }
     
    free(number);
    return 0;
}