兩數除法(判斷大小及除數是否為0)


#include 
#include 

using namespace std;

int main(void)
{
 int a, b;
 cout << "請輸入二個整數數值,以空白分隔:";
 cin >> a >> b;
 if(a >= b) {
  if(b == 0)
   cout << "除數為 0\n";
  else
   cout << a << " / " << b << " = " << (float)a/(float)b << endl;
 } else {
  if(a == 0)
   cout << "除數為 0\n";
  else
   cout << b << " / " << a << " = " << (float)b/(float)a << endl;
 }
    
    return 0;
}

這個網誌中的熱門文章

TCGS b004: 一個都不能少

使用memset加快二維陣列初始

UVA Q591:Box of Bricks