#include <stdio.h> void inverte(int *x, int n) { int *p, temp, *i, *j, m = (n - 1) / 2; i = x; j = x + (n - 1); p = x + m; for (i = x, j = x + (n - 1); i <= p; i++, j--) { temp = *i; *i = *j; *j = temp; } return 0; } int main() { void inverte(int *x, int n); int i; int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; printf("原数组为:\n"); for (i = 0; i < 10; i++) { printf("%d ", a[i]); } printf("\n"); inverte(a, 10); printf("交换后的数组为:\n"); for (i = 0; i < 10; i++) { printf("%d ", a[i]); } printf("\n"); return 0; } 方法二: #include <stdio.h> int main() { void inv(int b[], int n); int a[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int i; printf("原数组为:\n"); for (i = 0; i < 10; i++) { printf("%d ", a[i]); } printf("\n"); inv (a, 10); printf("交换后的数组为:\n"); for (i = 0; i < 10; i++) { printf("%d ", a[i]); } printf("\n"); return 0; } void inv (int b[], int n) { int i, j, temp, m; m = (n - 1) / 2; for (i = 0; i <= m; i++) { j = n - 1 - i; temp = b[i]; b[i] = b[j]; b[j] = temp; } }
原文:http://10706198.blog.51cto.com/10696198/1709357