冒泡法,為什么輸出來的結(jié)果一直不對? 求大神
#include<stdio.h>
int main()
{ ? ?int i,j,temp;
int score[]={67,98,75,63,82,79,81,91,66,84};
?for(j=0;j<9;j++) ? ? ? ? ? ? ?
for(i=0;i<9-j;i++) ? ? ? ? ??
if(score[i]>score[i+1])
{
//int temp;
temp=score[i]; ? ? ? ? ? ? ? ? ? // 中間是冒泡法求得從低到高排序;?
score[i]==score[i+1];
score[i+1]=temp;
}?
printf("\n");
for(j=0;j<10;j++)
printf("%d",score[j]);
return 0;
}
2015-07-30
找了半天,不厚道地笑了~~找一找,這2行代碼有何不同
發(fā)現(xiàn)了沒?上面的比下面的多了=。C語言中,==是等于的意思,=是賦值的意思。也就說你原先的代碼把數(shù)組后面的值都給賦值為98(數(shù)組里下標為1的值是98)。