/* Note:Your choice is C IDE */
#include "stdio.h"
#define N 45
int inputSS(char names [][20],int ccore[],int num);
void printSS(char names[][20],int score[],int num);
void getMAX(char names[][20],int score[],int num);
main()
{
char names[N][20];
int score[N];
int num=0;
int choose;
printf("What do you want to do:INPUT(1),OUTPUT(2),MAX(3),EXIT(0):");
scanf("%d",&choose);
do{
switch(choose){
case1:
num=inputSS(names,score,num);
break;
case2:
printSS(names,score,num);
break;
case3:
getMAX(names,score,num);
}
printf("\nWhat do you want to do:INPUT(1),OUTPUT(2),MAX(3),EXIT(0):");
scanf("%d",&choose);
}while(choose!=0);
}
int inputSS(char names[][20],int score[],int num){
int n,i;
printf("\nThis Time,How many students do you want to input:");
scanf("%d",&n);
if((n+num)>N||n<1){
printf("not valid sum\n");
return-1;
}
printf("NOW INPUT AS (NAME SCORE):\N");
for(i=0;i<n;i++){
printf("%d.",i);
scanf("%s%d",&names[i+num],&score[i+num]);
}
printf("THIS TIME,INPUT IS OVER\n");
return num+n;
}
void printSS(char names[][20],int score[],int num){
int i;
if(num==0){
printf("NO STUDENTS NOW\n");
return;
}
printf("\nNOW, THE STUDENTS SCORES AS FOLLOWS\n");
for(i=0;i<num;i++)
printf("%2d. name:%10s score:%3d\n",i,names[i],score[i]);
}
void getMAX(char names[][20],int score[],int num){
int i,max_index,max_score;
if(num==0){
printf("NO STUDENTS NOW\n");
return ;
}
max_index=0;
max_score=score[0];
for(i=1;i<num;i++)
if(score[i]>max_score){
max_score=score[i];
}
printf("The Top Score is %d by %s\n",score[max_index],names[max_index]);
}
520作业
最新推荐文章于 2022-10-03 13:38:05 发布