關(guān)于降序排列的!求助
#include <stdio.h>
int main()
{
? ? int score[10]={67,98,75,63,82,79,81,91,66,84};
? ??
? ? //總分
? ? int sum=0;
? ? int i;
? ? for(i=0;i<10;i++)
? ? {
? ? ? ? sum=sum+score[i];
? ? }
? ? printf("總分%d\n\n",sum);
? ??
? ? //最高分
? ? int max=0;
? ? int j;
? ? for(j=0;j<9;j++)
? ? {
? ? ? ? if(max<score[j])
? ? ? ? {max=score[j];}
? ? }
? ? printf("最高分%d\n\n",max);
? ??
? ? //最低分
? ? int min=200;
? ? int q;
? ? for(q=0;q<9;q++)
? ? {
? ? ? ? if(min>score[q])
? ? ? ? {min=score[q];}
? ? }
? ? printf("最低分%d\n\n",min);
? ??
? ? //平均分
? ? double avg=sum/10;
? ? printf("平均分%f\n\n",avg);
? ??
? ? //考試成績降序排列
? ? int temp;
? ? int m,n;
? ? printf("#####考試降序排列#####\n\n");
? ? for(m=0;m<9;m++)
? ? if(score[m]<score[m+1])
? ? {
? ? ? ? temp=score[m];
? ? ? ? score[m]=score[m+1];
? ? ? ? score[m+1]=temp;
? ? }
? ? for(n=0;n<10;n++)
? ? printf("%d ",score[n]);
? ??
? ??
? ??
? ??
? ? return 0;
}
--------------------------------------------------
最后降序排列這里為什么返回的值是未排序的?是全局變量什么的原因嗎?怎么修改?
2015-05-07
其實這個結(jié)合指針跟好的跟你解釋,但是現(xiàn)在沒學(xué)到指針。
for(m=0;m<9;m++)
? ? if(score[m]<score[m+1])
? ? {
? ? ? ? temp=score[m];
? ? ? ? score[m]=score[m+1];
? ? ? ? score[m+1]=temp;
? ? }
你把這段代碼外面再加上一個循環(huán),就是
這樣寫就行了