C语言数组倒序排列
#include <stdio.h>
#pragma mark 数组的倒序排列
int main()
{
int array[5] = {1, 3, 2, 4, 5};
/*方法一:*/
for (int i = 0; i<5/2; i++) {
int temp = array[i];
array[i] = array[4-i];
array[4-i] = temp;
}
/*方法二:*/
int i = 0, j = 4;
while (i<j) {
int temp = array[j];
array[j] = array[i];
array[i] = temp;
i++;
j--;
}
for (int k = 0; k<5; k++) {
printf("%d\t", array[k]);
}
return 0;
}