#include <stdio.h>
#define N 5
int main()
{
int arr[N];
int i;
int j;
int temp;
// step 1: get user input
for (i=0;i<N;i++)
{
printf("please enter an array element:\n");
scanf("%d", &arr[i]);
}
printf("\n");
// now start sorting
for (i=N;i>=0;i--)
{
for (j=0;j<i;j++)
{
if (arr[i]<arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
// output results
printf("the sorting result is:");
for (i=0;i<N;i++)
{
printf("%d ", arr[i]);
}
}
冒泡排序-C语言
最新推荐文章于 2024-09-08 20:02:08 发布