代码很简单,这里就不多废话了,直接奉上:
#include <iostream>using namespace std; int* reverse(int* list, int size){ for (int i = 0, j = size - 1; i < j; i++, j--) { // Swap list[i] with list[j] int temp = list[j]; list[j] = list[i]; list[i] = temp; } return list;} void printArray(int* const list, int size){ for (int i = 0; i < size; i++) cout << list[i] << " ";} int main(){ int list[] = {1, 2, 3, 4, 5, 6}; int* p = reverse(list, 6); printArray(p, 6); return 0;}
另附上一则网友的写法
#include<math.h>int main(void){ char c[100][100]; int i=0,j; char a; while (1) { scanf("%s%c",c[i],&a); if (a=='/n') { break; } i++; } for (j=i; j>=0; j--) { printf("%s ",c[j]); } return 0;}