数组逆置

#include<stdio.h>

void fun(int a[], int n){

int i,j,temp;

for(i = 0,j = n-1; i < j; i ++,j --){//  交换时 i< j即可完成   

temp = a[i];

a[i] = a[j];//

a[j] = temp;

}

for(j = 0;j < n; j++){

printf("%d",a[j]);

}

}

int main(void){

int a[]  = {1,2,3,4,5,6,7,8,9};

    fun(a,9);


return 0;


}


猜你喜欢

转载自blog.51cto.com/13645380/2154817