【20年扬大真题】
编写对数组求逆的递归算法
void swap(int* a, int* b) {int tmp = *b;*b = *a;*a = tmp;
}
void Ni(int arr[],int left,int right) {if (left > right) {return;}swap(&arr[left], &arr[right]);Ni(arr, left + 1, right - 1);
}
int main()
{int arr[20] = { 0 };//默认测试大小不超过20int n = 0;printf("请输入数组元素个数:");scanf("%d", &n);printf("\n");printf("请输入数组元素:");for (int i = 0;i < n;i++){scanf("%d", &arr[i]);}printf("\n");Ni(arr,0,n-1);printf("你输入的数组的逆为:");for (int i = 0;i < n;i++){printf("%d ", arr[i]);}return 0;
}