返回列表 發帖

if 判斷式 : 判斷數字大小





1. 輸入兩個數字至整數變數 a 與 b
2. 輸出 a 與 b
3. 輸出 a 與 b 的大小比較結果
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1.             #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.    
  6.     int score;
  7.     int level;
  8.     cout<<"請輸入您的分數:";
  9.     cin>>score;
  10.     cout<<"score=="<<score<<endl;
  11.     level=score/10;
  12.    
  13.     cout<<"您的評等是:";
  14.     switch(level)
  15.     {
  16.                
  17.      case 10:
  18.      case 9:     
  19.      cout<<"A"<<endl;
  20.      break;
  21.      case 8:   
  22.      cout<<"B"<<endl;

  23.      break;
  24.      case 7:
  25.      cout<<"C"<<endl;
  26.      break;                    
  27.       case 6:   
  28.       cout<<"D"<<endl;
  29.       break;
  30.       default:   
  31.       cout<<"E"<<endl;
  32.       break;   
  33.      }            
  34.                  
  35.     system("pause");
  36.     return 0;

  37. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>

  3. using  namespace  std;
  4. int main()
  5. {
  6.   int  score;
  7.   int  level;

  8.   cout<<"請輸入您的分數:";
  9.   cin>>score;
  10.   level= score / 10;

  11. switch(level)
  12. {
  13.              case 10:
  14.             
  15.              case 9:
  16.              cout<<"A"<<endl;
  17.              break;
  18.             
  19.              case 8:
  20.              cout<<"B"<<endl;
  21.              break;
  22.              case 7:
  23.              cout<<"C"<<endl;
  24.              break;
  25.               case 6:
  26.              cout<<"D"<<endl;
  27.              break;
  28.              default:
  29.              cout<<"E"<<endl;
  30.              break;
  31. }
  32.              system("pause");
  33.              return 0;
  34. }
複製代碼

TOP

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

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<<"b="<<b<<endl;
  13. if(a<b)
  14. {
  15. cout<<"a小於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. system("pause");
  26. return 0;         
  27. }
複製代碼

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<<" b = "<<b<<endl;
  13.    if(a > b)
  14.    cout<<"a大於b"<<endl;
  15.    if(a < b)
  16.    cout<<"a小於b"<<endl;
  17.    if(a = b)
  18.    cout<<"a等於b"<<endl;
  19.    
  20.    system("pause");
  21.    return 0;
  22. }
  23.      
複製代碼

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<<",b="<<b<<endl;

  13. if(a>b)
  14. {
  15.   cout<<"a大於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.     system("pause");
  26.     return 0;
  27. }
複製代碼

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 << ",b=" << b << endl;

  13. if (a > b)
  14. {
  15.     cout << "a大於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. system("pause");
  26. return 0;
  27. }
複製代碼

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.           system("pause");
  26.           return 0;
  27.           }
  28.      
複製代碼

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

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 <<",b=" << b << endl;
  13.     if(a < b)
  14.     {
  15.          cout << "a小於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.     system ("pause");
  26.     return 0;
  27. }   
複製代碼

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<<",b="<<b<<endl;
  13.   if(a > b)
  14.   {
  15.        cout<<"a 大於 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.     system("pause");
  26.              return 0;
  27.              }
複製代碼

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 <<", b =" <<b <<endl;
  13.    
  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.   
  9.   cout << "請輸入a:";
  10.   cin >> a;
  11.   cout << "請輸入b:";
  12.   cin >> b;
  13.   
  14.   cout << "a=" << a << ",b=" << b << endl;
  15.   
  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. #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 << "、b=" << b << endl;
  13.     if (a > b)
  14.     {
  15.     cout << "a大於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.     system ("pause");
  26.     return 0;
  27. }
複製代碼

TOP

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

  4. int main()
  5. {
  6.     int a;
  7.     int b;
  8.    
  9.     cout <<"請輸入 :";
  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.           system("pause");
  26.           return 0;
  27.           }
複製代碼

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

TOP

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

TOP

返回列表