返回列表 發帖

if...else if...else 判斷式 (一)

運用 if...else if...else 判斷式,比較 x 與 y 的大小關係。





  二擇一
  if( )
  {

  }
  else
  {

  }

  多擇一
  if( )
  {

  }
  else if( )
  {

  }
  else if( )
  {

  }
  else
  {

  }

  多擇多 / 多擇無
  if( )
  {
         
  }
  if( )
  {

  }
  if( )
  {

  }
  if( )
  {
         
  }
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x, y;
  7.     re:
  8.     cout<<"請輸入x: ";
  9.     cin>>x;
  10.     cout<<"請輸入y: ";
  11.     cin>>y;
  12.     if(x>y)
  13.         cout<<"x大於y!"<<endl;
  14.     else if(x<y)
  15.         cout<<"x小於y!"<<endl;
  16.     else
  17.         cout<<"兩數相等!"<<endl;
  18.     cout<<endl;
  19.     goto re;
  20.     system("pause");
  21.     return 0;
  22. }
複製代碼

返回列表