/* type型の二つの値を交換する関数形式マクロ swap(type, a, b) を定義せよ。たとえばint型の変数x, yの値が5と10であるとき、 swap(int, x, y)を呼び出した後は、 x, yには10と5が格納されていなければならない。 */ #include #define swap(type, a, b) { type tmp; tmp = a; a = b; b = tmp; } int main(void) { int x, y; float i, j; puts("二つの整数を入力してください"); printf("整数1:"); scanf("%d", &x); printf("整数2:"); scanf("%d", &y); swap(int, x, y); printf("整数1の値:%d\n", x); printf("整数2の値:%d\n", y); puts("二つの実数を入力してください"); printf("実数1:"); scanf("%f", &i); printf("実数2:"); scanf("%f", &j); swap(float, i, j); printf("実数1の値:%f\n", i); printf("実数2の値:%f\n", j); return 0; }