用宏定义实现函数值互换
生活随笔
收集整理的這篇文章主要介紹了
用宏定义实现函数值互换
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include<iostream>
#include<stdio.h>
#include<string>
#define swap(a,b){\int c;\c=a;\a=b;\b=c;\
}
using namespace std;
int main()
{int i, j, a[10], b[10];cout << "輸入十個數子在a中" << endl;for (i = 0; i < 10; i++)cin >> a[i];cout << "輸入十個數到b中" << endl;for (j = 0; j < 10; j++)cin >> b[j];cout << "顯示十個數" << endl;cout << "顯示a" << endl;for (i = 0; i < 10; i++)cout << a[i];cout << "輸出b" << endl;for (j = 0; j < 10; j++)cout << b[j];cout << "實現值的互換" << endl;for (i = 0; i < 10; i++)swap(a[i], b[i]);cout << "變換后的值" << endl;cout << "a的值" << a << endl;cout << "b的值" << b << endl;system("pause");return 0;
}
總結
以上是生活随笔為你收集整理的用宏定义实现函数值互换的全部內容,希望文章能夠幫你解決所遇到的問題。