用c++编写一个程序,将一数组中的元素反转。

2025-02-02 20:41:26
推荐回答(2个)
回答1:

void reverse(int *a, int n){//n为数组长度,a为数组的首地址
//传入进去的a数组将发生变化
int i = 0;
int temp;
for(i = 0; i < n/2; i++){
temp = a[i];
a[i] = a[n - i -1];
a[n - i -1] = temp
}
}

回答2:

typedef mytype yourtype;
mytype temp;
for ( int i=0 ; i{
temp=array[array_length-i];
array[array_length-i]=array[i];
array[i]=temp;
}