#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main(void)
{
int arr[5];//加上'\0'后由数组变成字符串
int i, j, temp;
printf("请输入五个数字:\n");
for (j = 0; j < 5; j++)
{
scanf("%d", &arr[j]);
}
for (i = 0; i < 5; i++)
{
for (j = 0; j < 5 - i - 1; j++)
{
if (arr[j] > arr[j + 1])//单增还是单减
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
system("cls");
printf("五个数字降序排序结果如下:\n\n");
for (i = 0; i < 5; i++)//排好序了;随便定义未知数输出
{
printf("\t%-10d\n\n", arr[i]);
}
return 0;
}
标签:arr,temp,++,冒泡排序,int,五个,printf From: https://blog.51cto.com/u_16073189/6273675