返回列表 發帖

五則運算(四)

  1. #include<iostream> // <-基本輸出輸入的函式庫 Input Output   cin 輸入 cout 輸出  
  2. #include<cstdlib> //主要的函式庫 Library
  3. using namespace std;
  4. int main()
  5. {
  6.     int x; int y;
  7.     cout << "兩數的五則運算" <<endl;
  8.     cout << "請輸入x的值:" <<endl;
  9.     cin >> x;
  10.     cout << "請輸入y的值:" <<endl;
  11.     cin >> y;
  12.    
  13.    
  14.   
  15.    
  16.     //正 正 = > 正
  17.     //正 負 = > 負
  18.     //負 正  = >負
  19.     //負 負 = > 正
  20.    
  21.    
  22.     // && and = > 兩者都要成立就回傳true
  23.     // || or  = > 兩者只要其中一者成立就回傳true  
  24.     // ! = > false
  25.     // 1 true 0 false
  26.     if(x!=0 && y!=0)//判斷條件是否符合  if內的判斷式如果成立就做括號內的事
  27.     {
  28.          //如果if內的條件不成立 就做else內括號的事
  29.          cout << "x+y=" << x+y << endl;
  30.          cout << "x-y=" << x-y << endl;
  31.          cout << "x*y=" << x*y << endl;
  32.          cout << "x/y=" << x/y << endl;
  33.          cout << "x%y=" << x%y << endl;
  34.     }
  35.     else{
  36.          cout << "x與y的值不可以為0 請重新輸入!" << endl;
  37.       
  38.     }
  39.    

  40.     system("pause");  
  41.     return 0;  
  42. }
複製代碼

返回列表