1 Star 0 Fork 0

Ash_Miku/ACM

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
【函数】绝对值排序 545 Bytes
一键复制 编辑 原始数据 按行查看 历史
Mars-Miku 提交于 2018-06-14 23:00 . Create 【函数】绝对值排序
#include <stdio.h>
#include <math.h>
#define N (100+5)
void mysort(float[], int);
int main()
{
float a[N];
int i, n;
while (scanf("%d",&n)!=EOF&&n!=0)
{
for (i = 0; i < n; i++)
scanf("%f", &a[i]);
mysort(a, n);
for (i = 0; i < n; i++)
{
printf("%.3f ", a[i]);
}
printf("\n");
}
return 0;
}
void mysort(float a[], int n)
{
int x, y;
float temp;
for (x = 1; x<n + 1; x++)
{
for (y = 0; y<n - x; y++)
{
if (fabs(a[y])>fabs(a[y + 1]))
{
temp = a[y];
a[y] = a[y + 1];
a[y + 1] = temp;
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ash_miku/ACM.git
[email protected]:ash_miku/ACM.git
ash_miku
ACM
ACM
master

搜索帮助