#include
#include
int main () {
int i,k,j,temp,geshu;
char hzstring[80];
strcpy(hzstring,"冒泡排序算法");
printf("%s\n", hzstring);
strcpy(hzstring,"请输入需要排序的正整数个数(2个以上)");
printf("%s\n", hzstring);
scanf("%d",&geshu);
if (geshu<2)
{
strcpy(hzstring,"需要排序的整数个数必须是2个以上,请重新运行程序");
printf("%s\n", hzstring);
return 0;
}
strcpy(hzstring,"请依次输入需要排序的正整数");
printf("%s\n", hzstring);
int a[geshu-1];
for(i=0;i<=geshu-1;i++)
{
scanf("%d",&a[i]);
};
for (i=0;ia[k+1])
{
temp=a[k];
a[k]=a[k+1];
a[k+1]=temp;
}
}
if(i<geshu-1)
{
strcpy(hzstring,"第");
printf("\n%s", hzstring);
printf("%d",i+1);
strcpy(hzstring,"轮冒泡结果:");
printf("%s\n", hzstring);
for(j=0;j<=geshu-1;j++)
{
printf("%d",a[j]);
if (j<geshu-1)
{
printf("%c", ',');
}
};
}
};
strcpy(hzstring,"最终排序结果如下:");
printf("\n%s\n", hzstring);
for(i=0;i<=geshu-1;i++)
{
printf("%d",a[i]);
if (i<geshu-1)
{
printf("%c", ',');
}
}
return 0;}