//输入5个数(含负数、小数)将它们按由小到大的顺序排列起来
//需要排数的数字通过参数传递进来
//例如:输入:./a.out -1 2.1 -3 5 7 输出:-3 -1 2.1 5 7
#include <stdio.h>
float sort(float b[5]);
int main()
{
int flag = -1;
int i;
float a[5];
printf("Please input 5 numbers:");
for(i = 0; i < 5; i++)
{
scanf("%f",&a[i]);
}
sort(a);
printf("The outcome is:");
for(i = 0;i < 5;i++)
{
printf("%g ",a[i]);
}
printf("\n");
return 0;
}
float sort(float b[])
{
int i,j;
float temp = 0.0;
for(i = 0;i < 5;i++)
{
for(j = i + 1;j < 5;j++)
{
if(b[j] < b[i])
{
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
}
由小到大排序(含负数、小数)
最新推荐文章于 2023-05-03 17:17:18 发布