题目:
将数组a中的n个整数按相反顺序存放
代码:
#include <stdio.h>
void inv(int *a,int len){
int temp,i,j,m=(len-1)/2;
for(i=0;i<=m;i++){
j=len-1-i;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
int main(){
int len,*p,i,a[10] = {3,7,9,11,0,6,7,5,4,2};
len = sizeof(a)/sizeof(a[0]);
printf("len is %d\n",len);
printf("请输入:\n");
for(p=a,i=0;p<(a+len) && i<len;p++,i++){
printf("a[%d]=",i);
scanf("%d",p);
}
for(p=a;p<(a+len);p++){
printf("%d ",*p);
}
p=a;
printf("\n");
inv(a,len);
for(p=a;p<(a+len);p++){
printf("%d ",*p);
}
return 0;
}
结果:
len is 10
请输入:
a[0]=1
a[1]=2
a[2]=3
a[3]=4
a[4]=5
a[5]=6
a[6]=7
a[7]=8
a[8]=9
a[9]=10
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
Process returned 0 (0x0) execution time : 3.449 s
Press any key to continue.
标签:10,题目,int,len,存放,数组,指针
From: https://www.cnblogs.com/blueBear-19210723/p/18552937