慕粉15600553655
2016-08-28 16:24
#include <stdio.h> #define N 10 void print(int score[]) { int i; for(i=0;i<N;i++) { if(i!=(N-1)) printf("%d,",score[i]); else printf("%d",score[i]); } int gettotal(int score[]) { int i; int total=0; for(i=0;i<N;i++) { total+=score[i]; } return total; } int getavg(int score[]) { return gettotal(score)/N; } int getmax(int score[]) { int i; int max=0; for(i=0;i<N;i++) { if(score[i]>max) { max=score[i]; } } return max; } int getmin(int score[]) { int i; int min=100; for(i=0;i<N;i++) { if(score[i]<min) { min=score[i]; } } return min; } void getsort(int score[]) { int i,j; for(i=N-2;i>=0;i--) { for(j=0;j<=i;j++) { if(score[j]<score[j+1]) { int temp; temp=score[j]; score[j]=score[j+1]; score[j+1]=temp; } } } int i; for(i=0;i<N;i++) { if(i!=(N-1)) printf("%d,",score[i]); else printf("%d",score[i]); } int main() { int score[N]={67,98,75,63,82,79,81,91,66,84}; int a,b,c,d; a=gettotal(score); b=getavg(score); c=getmax(score); d=getmin(score); printf("考试的总分%d\n",a); printf("最高分%d\n",b); printf("最低分%d\n",c); printf("平均分%d\n",d); getsort(score); return 0; }
这哪里错了,为什么得不出答案?
#include <stdio.h>
#define N 10
void printScore(int score[]){
int i;
printf("\n");
for(i=0;i<N;i++){
printf("%d\t",score[i]);
}
printf("\n");
}
int getTotalScore(int score[]){
int sum = 0;
int i;
for(i=0;i<N;i++){
sum+=score[i];
}
return sum;
}
int getAvgScore(int score[]){
return getTotalScore(score)/N;
}
int getMax(int score[]){
int max = -1;
int i;
for(i=0;i<N;i++){
if(score[i]>max){
max = score[i];
}
}
return max;
}
int getMin(int score[]){
int min = 100;
int i;
for(i=0;i<N;i++){
if(score[i]<min){
min=score[i];
}
}
return min;
}
void sort(int score[]){
int i,j;
for(i=N-2;i>=0;i--){
for(j=0;j<=i;j++){
if(score[j]<score[j+1]){
int temp;
temp = score[j];
score[j] = score[j+1];
score[j+1] = temp;
}
}
}
printScore(score);
}
int main()
{
int score[N]={67,98,75,63,82,79,81,91,66,84};
int sum,avg,max,min;
sum = getTotalScore(score);
avg = getAvgScore(score);
max = getMax(score);
min = getMin(score);
printf("总分是:%d\n",sum);
printf("平均分是:%d\n",avg);
printf("最高分是:%d\n",max);
printf("最低分是:%d\n\n",min);
printf("********成绩排名********\n");
sort(score);
return 0;
}
////
C语言入门
926021 学习 · 20793 问题
相似问题