透過使用者自行輸入數值 來計算簡單的五則運算- #include<cstdlib>
- #include<iostream> // I (Input)O (Output) 串流
- using namespace std;
- int main()
- {
- int x,y; //同時宣告x,y為int型別
-
- cout << "請輸入X的值\r\n";
- cin >> x;
- cout << "請輸入y的值\r\n";
- cin >> y;
-
- cout << "當x的值為:" <<x <<";當y的值為:" << y <<endl;
-
- cout << "x+y=" << x+y << endl;
- cout << "x-y=" << x-y << endl;
- cout << "x*y=" << x*y << endl;
- cout << "x/y=" << x/y << endl;
- cout << "x%y=" << x%y << endl;
-
- system("pause");
- return 0;
- }
複製代碼 |