怎么用c写一个成绩单·
从键盘上输入N名学生的姓名和某科成绩,按分数从高到低打印出成绩单。对非法数据,要求重新输入#include <stdio.h> #include <stdlib.h> struct Score_report { char name[7]; float grade; }; #define N 3 void Getsort(struct Score_report score[]); int main(void) { struct Score_report temp={0}; struct Score_report score[N]; int i, j; for(i=0; i<N; i++) { printf("Please enter the %d student's name and grade:\n", i+1); printf("Please you input the Name:"); scanf("%s", &score[i].name); printf("Please you input the Grade:"); scanf("%f", &score[i].grade); if(score[i].grade < 0.0 ||score[i].grade > 100.0) { printf("The grade you entered is not reasonable!\n"); printf("Please you re-enter:"); scanf("%f", &score[i].grade); } } for(i = 0; i < N-1; i++) { for(j = 0; j < N - 1 - i; j++) { if(score[j].grade < score[j+1].grade) { temp = score[j]; score[j] = score[j+1]; score[j+1] = temp; } } } printf("\n\n"); printf("*************Score report***************\n"); printf("\tName\tScore\n"); for(i=0; i<N; i++) { printf("\t%s\t%.1f\n", score[i].name, score[i].grade); } system("pause"); return 0; }
[此贴子已经被作者于2019-6-10 15:47编辑过]