成绩排名源代码
#include "stdio.h"
#include "stdlib.h"
#define N 5
void input(char *code[],char *name[],float *score1,float *score2,
float *score3,float *aver,int n);
void output(char *code[],char *name[],float *score1,float *score2,
float *score3,float *aver,int n,int j);
void sort(char *code[],char *name[],float *score1,float *score2,
float *score3, float *aver,int n);
void swap1(float *p1,float *p2);
void swap2(char **p1,char **p2);
main()
{char *code[N],*name[N];
float score1[N],score2[N],score3[N],aver[N];
input(code,name,score1,score2,score3,aver,N);
printf("\n");
output(code,name,score1,score2,score3,aver,N,1);
sort(code,name,score1,score2,score3,aver,N);
printf("\n");
output(code,name,score1,score2,score3,aver,N,2);
getch();
}
void input(char *code[],char *name[],float *score1,float *score2,
float *score3,float *aver,int n)
{int i;
for (i=0;i { printf("input No.%d:",i+1);
code[i]=malloc(8);
name[i]=malloc(12);
scanf("%s%s%f%f%f",code[i],name[i],&score1[i],&score2[i],&score3[i]);
aver[i]=(score1[i]+score2[i]+score3[i])/3.0;
}
printf("\n");
}
void output(char *code[],char *name[],float *score1,float *score2,
float *score3,float *aver,int n,int j)
{int i;
printf(" school report(%d) \n",j);
printf("----------------------------------------------------------------\n");
printf("code name score1 score2 score3 aver\n");
printf("----------------------------------------------------------------\n");
for (i=0;i {printf("%-10s%-14s%8.2f%8.2f%8.2f%8.2f\n",code[i],name[i],
score1[i],score2[i],score3[i],aver[i]);
}
}
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉