![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/e7cd7b899e510fb3d8fe4166d533c895d0430c5f?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
#include<
stdio.h>
int main()
{
int num=6,tep,sum=0;
int a[6]= {2,1,10,8,7,6};
int i,j;
printf("原数组:");
for(int p=0; p<num; p++)
printf("%d ",a[p]);
puts("");
for(i=0; i<num-1; i++)
{
for(j=0; j<num-i; j++)
{
if(a[j]>a[j+1])
{
tep=a[j];
a[j]=a[j+1];
a[j+1]=tep;
}
sum++;
}
printf("第%d趟排序后:",i+1);
for(int p=0; p<num; p++)
printf("%d ",a[p]);
printf("此时总比较次数:%d\n",sum);
}
return 0;
}