為什么這里的語(yǔ)句需要用到for嵌套?
#include <stdio.h>
void sortScore(int score[])
{
? ? int i,j,temp;
? ? for(i=0;i<=8;i++)
? ? {
? ? ? ? for(j=0;j<=8;j++)
? ? ? ? {
? ? ? ? ? ? if(score[j]>score[j + 1])
? ? ? ? ? ? {
? ? ? ? ? ? ? ? temp = score[j];
? ? ? ? ? ? ? ? score[j] = score[j + 1];
? ? ? ? ? ? ? ? score[j + 1] = temp;
? ? ? ? ? ? }
? ? ? ? }
? ? }
} ??
int main()
{ ??
? ? int i;
? ? int score[10]={67,98,75,63,82,79,81,91,66,84};
? ? sortScore(score);
? ? for(i=0;i<=9;i++)
? ? {
? ? ? ? printf("%d ",score[i]);
? ? }
? ? return 0;
}
2016-11-28
冒泡排序