闲时弄月
2016-12-31 12:45
#include <stdio.h> #define N 10 int sum(int score[]) //计算总分 { int i; int s = 0; for(i=0; i<N; i++) { s += score[i]; } return s; } int va(int score[]) //计算平均分 { return (sum(score)+0.0)/N; } void des(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; } } } for(i=0;i<N;i++) { if(i != 9) printf("%d, ", score[i]); else printf("%d", score[i]); } printf("\n"); } int max(int score[]) //最大值 { int j,m; for(j=0;j<=N-2;j++) { if(score[j]>score[j+1]) { score[j+1] = score[j]; m = score[j+1]; } } return m; } int min(int score[]) //最小值 { int j,n; for(j=0;j<=N-2;j++) { if(score[j]<score[j+1]) { score[j+1] = score[j]; n = score[j+1]; } } return n; } int main() { int score[N]={67,98,75,63,82,79,81,91,66,84}; int i,s,v,mx,mn; s = sum(score); v = va(score); mx = max(score); mn = min(score); printf("考试总分:%d\n",s); printf("考试平均分:%d\n",v); printf("考试成绩最高分:%d\n",mx); printf("考试成绩最低分:%d\n",mn); printf("考试成绩降序排列:\n"); des(score); }
{score[j+1] = score[j];
m = score[j+1]; }
{ score[j+1] = score[j];
n = score[j+1]; }
最大值,最小值那里直接m=score[j];n=score[j];你把他们赋值成一样的了
都没问题啊 我试了下 没有问题
C语言入门
926021 学习 · 20793 问题
相似问题