编写一个函数,要求用指向指针的方法対n个整数排序并输出。用户c语言实现
1个回答
展开全部
#include <STDIO.H>
#define N 10
int Px(int num[])
{
int i, j;
for ( i = 0; i < N; i++ )
for ( j = 0; j < N - 1 - i; j++ )
{
if (num[j] < num[j + 1])
{
int temp;
temp = num[j];
num[j] = num[j + 1];
num[j + 1] = temp;
}
}
}
main()
{
int num[N], i;
printf ("Please input the numbers: ");
for ( i = 0; i < N; i++ )
{
scanf ("%d", &num[i]);
}
Px(&num);
for ( i = 0; i < N; i++ )
{
printf ("%d ", num[i]);
}
}
#define N 10
int Px(int num[])
{
int i, j;
for ( i = 0; i < N; i++ )
for ( j = 0; j < N - 1 - i; j++ )
{
if (num[j] < num[j + 1])
{
int temp;
temp = num[j];
num[j] = num[j + 1];
num[j + 1] = temp;
}
}
}
main()
{
int num[N], i;
printf ("Please input the numbers: ");
for ( i = 0; i < N; i++ )
{
scanf ("%d", &num[i]);
}
Px(&num);
for ( i = 0; i < N; i++ )
{
printf ("%d ", num[i]);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询