谢谢您的回答 可是还有一道跟它相关的题
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/11 16:19:34
谢谢您的回答 可是还有一道跟它相关的题
#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 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 <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;
}
#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;
}