C语言数组排序
C语言数组排序
这是倒序,不是排序。
下面代码运行结果:
输入n: 输入6个数: 12 15 29 38 220 4倒序后: 44 220 38 29 15 12
#include
#define N 25void inverse(int *in, int *out, int n)
{
int i
for(i = 0 i < n i ){
out[i] = in[n-1-i]
}
}
int main()
{
int in[N]
int out[N]
int n = 0
int i = 0
printf("输入n: ")
scanf("%d", &n)
if(n > N) n = N
printf("输入%d个数: ", n)
for(i = 0 i < n i ){
if(scanf("%d", in i)!=1) break
}
n = i
inverse(in, out, n)
printf("倒序后: ")
for(i = 0 i < n i ){
printf("%d ", out[i])
}
printf("
")
return 0
}