编写一个函数void funint p int n其功能为对整数数组p5中的数字进行排序。排序结果在主函数中输出。 输入: 34 78 23 12 69 输出如下: 7869342312
#include <stdio.h>
void fun(int *p, int n)
{
int i, j, temp;
for (i = 0; i < n-1; i++)
{
for (j = 0; j < n-i-1; j++)
{
if (p[j] < p[j+1])
{
temp = p[j];
p[j] = p[j+1];
p[j+1] = temp;
}
}
}
}
int main()
{
int a[5] = {34, 78, 23, 12, 69};
int i;
fun(a, 5);
for (i = 0; i < 5; i++)
{
printf("%d", a[i]);
if (i != 4)
{
printf(",");
}
}
return 0;
}
``
原文地址: https://www.cveoy.top/t/topic/daL1 著作权归作者所有。请勿转载和采集!