為什么輸出會上樣 :排序之后 84668181796363676767
#include <stdio.h>
int main()
{
? ? int score[]={67,98,75,63,82,79,81,91,66,84};
? ? int i,j,temp;
? ? for(i=8;i>=0;i--)
? ? {
? ? ? ? for(j=0;j<=i;j++)
? ? ? ? {
? ? ? ? ?if (score[j]<score[j+1])
? ? ? ? ?
? ? ? ? ?temp=score[j];
? ? ? ? ?score[j]=score[j+1];
? ? ? ? ?score[j+1]=temp;
? ? ? ? ?}
? ? } ?
? ? printf("\n排序之后\n");
? ? ? for(i=0;i<10;i++)
? ? {
? ? ? ? if(i !=9)
? ? ? ? printf("%d",score[i]); ??
? ? else
? ? ? ? printf("%d" ,score[i]);
? ? }
? ? return 0;
}
2016-11-04
if條件后如果有多條語句必須要加“{}”,否則只會跳過第一條語句,而后面的語句還會執(zhí)行。另外還要記得使用tab鍵縮進。
2016-11-04
你的if語句沒有加花括號!