C语言实现冒泡排序
#include <stdio.h>
#include <stdlib.h>
int main() {
int arr[] = {81,34,28,33,87,65,66,56};
int i,j;
for (i = 8; i > 0 ; i--)
{
for(j = 0; j <= i; j++)
{
if(arr[j] > arr[j+1])
{
int temp;
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
for (int i = 0; i < 8; i++)
{
if(i != 7)
printf("%d, ", arr[i]);
else
printf("%d\n", arr[i]);
}
return 0;
}
网友评论