69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
typedef struct message{
int number;
char name[100];
int ordinary;
int midterm;
int endterm;
}Message;
typedef struct link{
Message *stu;
struct Link *next;
}Link;
int main()
{
Link *head = (Link*)malloc(sizeof(Link)), *tail = head;
head->stu = NULL;
head->next = NULL;
Message *tmp;
int n = 0;
printf("input students' number:");
scanf("%d", & n);
int m = n;
printf("circle input %d students message\n", n);
while(n--){
tmp = (Message*)malloc(sizeof(Message));
printf("input student's message\n");
scanf("%d %s %d %d %d", &(tmp->number), tmp->name, &(tmp->ordinary), &(tmp->midterm), &(tmp->endterm));
tail->next = (Link*)malloc(sizeof(Link));
tail = tail->next;
tail->stu = tmp;
}
int total[10] = {0};
tail = head;
while(tail->next != NULL){
tail = tail->next;
int score = tail->stu->ordinary * 0.2 + tail->stu->midterm * 0.3 + tail->stu->endterm * 0.5;
printf("ID:%d NAME:%s SCORE:%d\n", tail->stu->number, tail->stu->name, score);
total[score / 10 - 1]++;
}
int i = 0;
for(i = 0; i < 10 ; i++){
if(total[i] == 0) continue;
printf("%2d-%3d: %d/%d\n", i * 10, (i + 1) * 10, total[i], m);
}
return 0;
}
不好意思, 这个才是#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
struct Message{
int number;
char name[100];
int ordinary;
int midterm;
int endterm;
};
struct link{
Message *stu;
link *next;
};
int main()
{
link *head = (link*)malloc(sizeof(link)), *tail = head;
head->stu = NULL;
head->next = NULL;
Message *tmp;
int n = 0;
printf("input students' number:");
scanf("%d", & n);
int m = n;
printf("circle input %d students message\n", n);
while(n--){
tmp = (Message*)malloc(sizeof(Message));
printf("input student's message\n");
scanf("%d %s %d %d %d", &(tmp->number), tmp->name, &(tmp->ordinary), &(tmp->midterm), &(tmp->endterm));
tail->next = (link*)malloc(sizeof(link));
tail = tail->next;
tail->stu = tmp;
}
int total[10] = 0;
tail = head;
while(tail->next != NULL){
tail = tail->next;
int score = tmp->ordinary * 0.2 + tmp->midterm * 0.3 + tmp->endterm * 0.5;
printf("ID:%d NAME:%s SCORE:%d\n", tail->number, tail->name, score);
total[score / 10 - 1]++;
}
for(int i = 0; i < 10 ; i++){
printf("%d-%d: %f\n", i * 10, (i + 1) * 10, total[i] / m);
}
return 0;
}