#include <stdio.h>
// swap関数:2つのポインタが指す値を入れ替える
void swap(int *x, int *y) {
int temp = *x;
*x = *y;
*y = temp;
}
int main() {
int data1[5] = {1, 2, 3, 4, 5}; // 配列data1を初期化
int data2[5] = {6, 7, 8, 9, 10}; // 配列data2を初期化
// 配列の要素を1つずつ入れ替え
for (int i = 0; i < 5; i++) {
swap(&data1[i], &data2[i]);
}
// 入れ替え後の配列を表示
printf("入れ替え後のdata1: ");
for (int i = 0; i < 5; i++) {
printf("%d ", data1[i]);
}
printf("\n");
printf("入れ替え後のdata2: ");
for (int i = 0; i < 5; i++) {
printf("%d ", data2[i]);
}
printf("\n");
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyBzd2Fw6Zai5pWw77yaMuOBpOOBruODneOCpOODs+OCv+OBjOaMh+OBmeWApOOCkuWFpeOCjOabv+OBiOOCiwp2b2lkIHN3YXAoaW50ICp4LCBpbnQgKnkpIHsKICAgIGludCB0ZW1wID0gKng7CiAgICAqeCA9ICp5OwogICAgKnkgPSB0ZW1wOwp9CgppbnQgbWFpbigpIHsKICAgIGludCBkYXRhMVs1XSA9IHsxLCAyLCAzLCA0LCA1fTsgLy8g6YWN5YiXZGF0YTHjgpLliJ3mnJ/ljJYKICAgIGludCBkYXRhMls1XSA9IHs2LCA3LCA4LCA5LCAxMH07IC8vIOmFjeWIl2RhdGEy44KS5Yid5pyf5YyWCgogICAgLy8g6YWN5YiX44Gu6KaB57Sg44KSMeOBpOOBmuOBpOWFpeOCjOabv+OBiAogICAgZm9yIChpbnQgaSA9IDA7IGkgPCA1OyBpKyspIHsKICAgICAgICBzd2FwKCZkYXRhMVtpXSwgJmRhdGEyW2ldKTsKICAgIH0KCiAgICAvLyDlhaXjgozmm7/jgYjlvozjga7phY3liJfjgpLooajnpLoKICAgIHByaW50Zigi5YWl44KM5pu/44GI5b6M44GuZGF0YTE6ICIpOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCA1OyBpKyspIHsKICAgICAgICBwcmludGYoIiVkICIsIGRhdGExW2ldKTsKICAgIH0KICAgIHByaW50ZigiXG4iKTsKCiAgICBwcmludGYoIuWFpeOCjOabv+OBiOW+jOOBrmRhdGEyOiAiKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgNTsgaSsrKSB7CiAgICAgICAgcHJpbnRmKCIlZCAiLCBkYXRhMltpXSk7CiAgICB9CiAgICBwcmludGYoIlxuIik7CgogICAgcmV0dXJuIDA7Cn0=