【数组按位置对调】2022-11-20
缘由C语言的数组互换问题-编程语言-CSDN问答
void 数组按位置对调(int* a, int n, int x)
{//缘由https://ask.csdn.net/questions/7840857/53991625?spm=1001.2014.3001.5501int t = 0;z:if (x < n){ t = a[x - n / 2] - a[x], a[x - n / 2] -= t, a[x] += t, ++x;goto z;}
}int a[10]{}, x = 0;//36 43 41 62 20 29 72 17 0 41r0:if (x < 10){ std::cin >> a[x], ++x; goto r0; }数组按位置对调(a, 10, 5); x = 0;c0:if (x < 10){ std::cout << a[x] << " ", ++x; goto c0; }std::cout << "\n";