c语言:(指针)有n个数按输入时顺序的逆序排序,用函数实现
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define n 10
int main(){
void fun(int *p,int a);
int a;
printf("输入几个数字:\n");
scanf("%d",&a);
int *p = malloc(80*sizeof(int));
for (int i = 0; i < a; i++)
{
printf("输入第%d个数字:",i+1);
scanf("%d",p+i);
}
fun(p,a);
return 0;
}
void fun(int *p,int a){
for (int i = a - 1; i >= 0; i--) //正序i=0,1,2... i<a 那么逆序不就是反过来5,4,3...嘛
{
printf("%d\t",*(p+i)); //*(p+i) = p[i]
}
}