返回列表 發帖

if 判斷式

讓使用者輸入兩個數字,把數字顯示出來後同時對這兩個數字進行比較,並把比較結果顯示出來。

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

TOP

本帖最後由 呂嘉勳 於 2014-7-3 11:18 編輯
  1. #include <iostream>
  2. #include <cstdlib>
  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.       if (a>b)
  15.       {
  16.               cout<<"a大於b"<<endl;
  17.               }   
  18.          if (a<b)
  19.          {
  20.           cout<<"a小於b"<<endl;
  21.           }
  22.            if (a==b)
  23.            {
  24.             cout<<"a等於b"<<endl;        
  25.                     }               
  26.     system("pause");
  27.     return 0;
複製代碼

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.    
  31.    
  32.    system("pause");
  33.     return 0;
複製代碼

TOP

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

  28.     system("pause");
  29.     return 0;
  30. }
複製代碼

TOP

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

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     int i;
  8.     cout << "請輸入a"<<endl;
  9.     cin >> a;
  10.     cout << "請輸入i"<<endl;
  11.     cin >> i;
  12.    
  13.     cout << "a="<<a<<endl;
  14.     cout << "i="<<i<<endl;

  15.     if(a>i)
  16.     {
  17.         cout<<"a>i"<<endl;
  18.     }
  19.     IF(I>A)
  20.     {
  21.           COUT<<"I>A"<<endl;
  22.     }
  23.     if(a==i)
  24.     {
  25.             cout<<"a=i"<<endl;        
  26.     }      
  27.     system("pause");
  28.     return 0;
  29. }
複製代碼

TOP

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int a;
    int b;
    cout << "請輸入a";
    cin >> a;
    cout << "請輸入b";
    cin >> b;
    cout << "a=" << a << endl;
    cout << "b=" << b << endl;
    if(a > b)
{   
    cout << "a 大於 b"<< endl;
}   
    if(a < b)
{   
    cout << "a 小於 b"<< endl;
}   
{   
    if(a == b)
    cout << "a 等於 b"<< endl;
}   
    system("pause");
    return 0;
}

TOP

  1.    #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    
  7.     int a;
  8.     int b;
  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.    
  22.      if(a<b)
  23.      {
  24.             
  25.             cout<<"a小於b"<<endl;
  26.      }
  27.      if(a==b)
  28.      {
  29.             cout<<"a等於b"<<endl;   
  30.      }      
  31.     system("pause");
  32.     return 0;
複製代碼

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.     if (a < b)
  21.     {
  22.      cout <<"a 小於 b"<< endl;
  23.     }
  24.     if (a == b)
  25.     {
  26.       cout <<"a 等於 b"<< endl;   
  27.     }
  28.          
  29.     system ("pause");
  30.     return 0;   
  31. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  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.     if(a > b)
  15. {   
  16.     cout << "a 大於 b"<< endl;
  17. }   
  18.     if(a < b)
  19. {   
  20.     cout << "a 小於 b"<< endl;
  21. }   
  22. {   
  23.     if(a == b)
  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.    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.    
  31.    
  32.    system("pause");
  33.     return 0;
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  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.     if(a>b)
  15.     {
  16.            cout<<"a大於b"<<endl;
  17.     }
  18.     if(a<b)
  19.     {
  20.            cout<<"a小於b"<<endl;
  21.     }
  22.     if(a==b)
  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.     cout<<"請輸入a"<< endl;
  9.     cin>> a;
  10.     cout<<"請輸入b"<< endl;
  11.     cin>> b;
  12.     cout<<"a="<< a << endl;
  13.     cout<<"b="<< b << endl;
  14.     cout<<"帥啦"<< endl;
  15.     if (a > b)
  16.     {
  17.     cout<<"a > b"<< endl;
  18.     }
  19.     if (a < b)
  20.     {
  21.     cout<<"a < b"<< endl;
  22.     }
  23.     if (a == b)
  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.     cout<<"請輸入a"<<endl;
  9.     cin>>a;
  10.     cout<<"請輸入b";
  11.     cin>>b;
  12.     cout<<"a="<<a<<endl;
  13.     cout<<"b="<<b<<endl;
  14.     if(a>b)
  15.     {
  16.      cout<<"a大於b"<<endl;      
  17.     }
  18.     if(a<b)
  19.     {
  20.      cout<<"a小於b"<<endl;      
  21.     }
  22.     if(a==b)
  23.     {
  24.      cout<<"a等於b"<<endl ;      
  25.     }
  26.    
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    for(int i=1;i<10;i++)
  7.    {
  8.        cout<<"第"<<i<<"位"<<endl;   
  9.    }
  10.    system("pause");
  11.    return 0;
  12. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  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.             
  13.     cout<<"a="<<a<<endl;
  14.     cout<<"b="<<b<<endl;
  15.      
  16.     if(a>b)
  17.     {
  18.         cout<<"a<b"<<"吃土吧你,說甚麼a大於b"<<endl;
  19.     }      
  20.     if(a<b)
  21.     {
  22.         cout<<"a<b"<<"去死吧你,居然是a小於b"<<endl;     
  23.     }  
  24.     if(a==b)
  25.     {
  26.            cout<<"a=b"<<"都被騙了,就說其實是a等於b"<<endl;
  27.     }      
  28.     system("pause");
  29.     return 0;
  30. }
複製代碼

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.     cout<<"a="<<a<<endl;   
  14.     cout<<"b="<<b<<endl;
  15.     if (a>b)
  16.     {
  17.     cout<<"a大於b"<<endl;        
  18.             }
  19.    
  20.      if (a<b)
  21.     {
  22.     cout<<"a小於b"<<endl;        
  23.             }
  24.            
  25.      if (a==b)
  26.     {
  27.     cout<<"a等於b"<<endl;        
  28.             }        
  29.    
  30.   system("pause");
  31.   return 0;   
  32. }
複製代碼

TOP

返回列表