返回列表 發帖

if...else if...else 判斷式

本帖最後由 tonyh 於 2016-8-4 14:57 編輯





  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a, b;
  7.     cout<<"請輸入a: ";
  8.     cin>>a;
  9.     cout<<"請輸入b: ";
  10.     cin>>b;
  11.     if(a>b)
  12.     {
  13.        cout<<"a>b"<<endl;
  14.     }else if(a<b)
  15.     {
  16.        cout<<"a<b"<<endl;   
  17.     }else
  18.     {
  19.        cout<<"a=b"<<endl;   
  20.     }
  21.     system("pause");
  22.     return 0;   
  23. }
  24. /*
  25.    
  26.    >   大於
  27.    <   小於
  28.    ==  等於
  29.    >=  大於或等於
  30.    <=  小於或等於
  31.    !=  不等於
  32.    
  33. */
複製代碼

  1. #include<cstdlib>
  2. using namespace std;
  3. int main()
  4. {
  5.     int a, b;
  6.     cout<<"請輸入a:";
  7.     cin>>a;
  8.     cout<<"請輸入b:";
  9.     cin>>b;
  10.     cout<<"a="<<a<<endl;
  11.     cout<<"b="<<b<<endl;
  12.     if(a>b)
  13.     {
  14.            cout<<"a>b"<<endl;
  15.     }
  16.     else if(a<b)
  17.     {
  18.            cout<<"a<b"<<endl;
  19.     }
  20.     else
  21.     {
  22.            cout<<"a=b"<<endl;
  23.     }
  24.     system("pause");
  25.     return 0;   
  26. }
複製代碼

TOP

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

TOP

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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a, b;
  7.     cout<<"請輸入a:";
  8.     cin>>a;
  9.     cout<<"請輸入b:";
  10.     cin>>b;
  11.    
  12.     if(a>b)
  13.     {
  14.            cout<<"a>b"<<endl;
  15.     }
  16.     else if(a<b)
  17.     {
  18.            cout<<"a<b"<<endl;
  19.     }
  20.     else
  21.     {
  22.            cout<<"a=b"<<endl;
  23.     }
  24.     system("pause");
  25.     return 0;   
  26. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int a;
  7.     int b;
  8.    
  9.     cout << "請輸入 a:";
  10.     cin >> a;
  11.      cout << "請輸入 b:";
  12.     cin >> b;
  13.    
  14.     cout << "a=" <<a<< endl;
  15.     cout << "b=" <<b<< endl;
  16.    
  17.     if(a < b)
  18.     {
  19.          cout << "a 大於 b" << endl;
  20.     }
  21.     if(a < b)
  22.     {
  23.          cout << "a 小於 b" << endl;
  24.     }
  25.     if(a < b)
  26.     {
  27.          cout << "a 等於 b" << endl;
  28.     }
  29.    
  30.     system("pause");
  31.     return 0;
  32. }
複製代碼

TOP

  1. #clude<iostream>
  2. #clude<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.         int a,b;
  7.         
  8.         cout<<"請輸入a:";
  9.         cin>>a;
  10.         cout<<"請輸入b:";
  11.         cin>>b;
  12.         
  13.         cout<<"a="<<a<<endl;
  14.         cout<<"b="<<a<<endl;
  15.         if(a>b)
  16.         {
  17.           cout<<"a>b"<<endl;
  18.         }
  19.         else if(a<b)
  20.         {
  21.           cout<<"a<b"<<endl;
  22.         }else
  23.         {
  24.           cout<<"a=b"<<endl;
  25.         }
  26.         system("pause")
  27.         return 0
  28. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int a;
  7.     int b;
  8.    
  9.     cout<<"請輸入a";
  10.     cin>>a;
  11.     cout<<"請輸入b";
  12.     cin>>b;
  13.    
  14.     if(a>b)
  15.     {
  16.         cout<<"a>b"<<endl;
  17.     }else if(a<b)
  18.     {
  19.         cout<<"a<b"<<endl;
  20.     }else
  21.     {
  22.         cout<<"a=b"<<endl;
  23.     }                    
  24.    
  25.     system("pause");
  26.     return 0;
  27. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a,b;
  7.     cout<<"請輸入a:";
  8.     cin>>a;
  9.     cout<<"請輸入b:";
  10.     cin>>b;
  11.    
  12.     cout<<"a="<<a<<endl;
  13.     cout<<"b="<<b<<endl;
  14.    
  15.     if(a>b)
  16.     {
  17.          cout<<"a大於b"<<endl;
  18.     }
  19.     else if(a<b)
  20.     {
  21.          cout<<"a小於b"<<endl;
  22.     }
  23.     else
  24.     {
  25.          cout<<"a等於b"<<endl;
  26.     }                             
  27.     system("pause")
  28.     return 0;
  29. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int a;
  7.     int b;
  8.    
  9.     cout<<"請輸入a";
  10.     cin>>a;
  11.     cout<<"請輸入b";
  12.     cin>>b;
  13.    
  14.     cout<<"a="<<a<<endl;
  15.     cout<<"b="<<b<<endl;
  16.    
  17.     if(a>b)
  18.     {
  19.          cout<<"a大於b"<<endl;
  20.     }
  21.      else if(a<b)
  22.     {
  23.          cout<<"a小於b"<<endl;
  24.     }
  25.      else
  26.      {
  27.         cout<<"a等於b"<<endl;
  28.      }      
  29.     system("pause");
  30.     return 0;
  31.     }
複製代碼

TOP

  1. #include<iostream>
  2. #include<iostream>
  3. using namespace std;

  4. int main()
  5. {
  6.     int a;
  7.     int b;
  8.     cout<<"請輸入a:";
  9.     cin>>a;
  10.     cout<<"請輸入b:";
  11.     cin>>b;
  12.     cout<<"a="<<a<<endl;
  13.     cout<<"b="<<b<<endl;
  14.    
  15.     if(a>b)
  16.     {
  17.          cout<<"a大於b"<<endl;
  18.     }
  19.     else if(a<b)
  20.     {
  21.          cout<<"a小於b"<<endl;
  22.     }
  23.     else   
  24.     {
  25.          cout<<"a等於b"<<endl;     
  26.     }     
  27.     system("pause");
  28.     return 0;
  29. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int a, b;
  7.    
  8.     cout<<"請輸入a:";
  9.     cin>>a;
  10.     cout<<"請輸入b:";
  11.     cin>>b;
  12.    
  13.     if(a>b)
  14.     {
  15.            cout<<"a>b"<<endl;
  16.     }else if(a<b){
  17.            cout<<"a<b"<<endl;
  18.     }else{
  19.           cout<<"a=b"<<endl;
  20.     }
  21.    
  22.     system("pause");
  23.     return 0;
  24.     }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.    int a;
  7.    int b;
  8.    
  9.    cout<<"請輸入a:";
  10.    cin>>a;   
  11.    cout<<"請輸入b:";
  12.    cin>>b;
  13.    
  14.    cout<<"a="<<a<<endl;
  15.    cout<<"b="<<b<<endl;

  16.    if(a>b)
  17.    {
  18.         cout<<"a大於b"<<endl;
  19.    }
  20.    else if (a<b)
  21.    {   
  22.         cout<<"a小於b"<<endl;
  23.    }
  24.    else
  25.    {
  26.         cout<<"a等於b"<<endl;
  27.    }
  28.    
  29.    system("pause")
  30.    return 0;
  31. }
複製代碼

TOP

  1. int main()
  2. {   
  3.     int a,b;
  4.     cout<<"請輸入a: ";
  5.     cin>>a;
  6.     cout<<"請輸入b: ";
  7.     cin>>b;
  8.     cout<<"a="<<a<<endl;
  9.     cout<<"b="<<b<<endl;
  10.     if(a>b)
  11.     {
  12.        cout<<"a大於b"<<endl;   
  13.     }else if(a<b)
  14.     {
  15.        cout<<"a小於b"<<endl;  
  16.     }else
  17.     {
  18.        cout<<"a等於b"<<endl;  
  19.     }  
  20.          
  21.     system("pause");
  22.     return 0;
  23. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int a;
  7.     int b;
  8.    
  9.     cout<<"請輸入 a:";
  10.     cin>>a;
  11.     cout<<"請輸入 b:";
  12.     cin>>b;
  13.    
  14.     cout<<"a="<<a<<endl;
  15.     cout<<"b="<<b<<endl;
  16.    
  17.     if(a>b)
  18.     {
  19.       cout<<"a 大於 b"<<endl;
  20.     }
  21.     else if(a<b)
  22.     {
  23.       cout<<"a 小於 b"<<endl;
  24.     }
  25.     else
  26.     {
  27.          cout<<"a 等於 b"<<endl;
  28.     }
  29.    
  30.     system("pause");
  31.     return 0;
  32. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int a;
  7.     int b;
  8.    
  9.     cout<<"請輸入a:";
  10.     cin>>a;
  11.     cout<<"請輸入b:";
  12.     cin>>b;
  13.    
  14.     cout<<"a="<<a<<endl;
  15.     cout<<"b="<<b<<endl;
  16.    
  17.     if(a<b)
  18.     {
  19.             cout<<"a大於b"<<enle;
  20.             }
  21.             else ug (a<b)
  22.             {
  23.              cout<<"a小於b"<<endl;
  24.              }
  25.              else
  26.              {
  27.                  cout<<"a等於b"<<endl;
  28.                  }
  29.                  
  30.                  system("pause");
  31.                  restem 0;
  32. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstblid>
  3. using namespace std;

  4. int main()
  5. {
  6.     int a;
  7.     int b;
  8.    
  9.     cout<<"請輸入a;";
  10.     cin>>a;
  11.     cout<<"請輸入b;";
  12.     cin>>b;
  13.    
  14.     cout,,<<"a="<<a<<endl;
  15.     cout,,<<"b="<<b<<endl;
  16.     if(a>b)
  17.     {
  18.            cout<<"a大於b"<<endl;
  19.     }
  20.     else if(a<b)
  21.     {
  22.          cout<<"a小於b"<<endl;
  23.     }
  24.     else
  25.     {
  26.          cout<<"a等於b"<<endl;
  27.     }
  28.     system("pause");
  29.     return 0;
  30. }
複製代碼
回復 1# tonyh

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a,b;
  7.    
  8.     cout<<"請輸入a:";
  9.     cin>>a;
  10.     cout<<"請輸入b:";
  11.     cin>>b;
  12.    
  13.     cout<<"a="<<a<<endl;
  14.     cout<<"b="<<b<<endl;
  15.    
  16.     if(a>b)
  17.     {
  18.           cout<<"a大於b"<<endl;
  19.     }else if(a<b)
  20.     {
  21.           cout<<"a小於b"<<endl;
  22.     }else
  23.     {
  24.          cout<<"a等於b"<<endl;
  25.     }
  26.     system("pause");
  27.     return 0;
  28. }   
複製代碼

TOP

返回列表