返回列表 發帖
  1. #include<cstdlib>
  2. #include<iostream>
  3. #include<Math.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     int m;
  8.     float a,b;
  9.     cout<<"請選擇圖形:1.圓形 2.三角形"<<endl;
  10.     cin>>m;
  11.     switch(m)
  12.     {
  13.     case 1:
  14.           cout<<"請輸入圓形的半徑:";
  15.           cin>>a;
  16.           cout<<"此圓形的面積為:"<<(a*a*M_PI)<<endl;
  17.           break;
  18.     case 2:
  19.           cout<<"請輸入三角形的高:";
  20.           cin>>a;
  21.           cout<<"請輸入三角形的底:";
  22.           cin>>b;
  23.           cout<<"此三角形的面積為:"<<(a*b)/2<<endl;
  24.           break;
  25.     default:
  26.           cout<<"ERROR!ERROR!"<<endl;
  27.           break;        
  28.     }
  29.     system("pause");
  30.     return 0;
  31. }
複製代碼

TOP

返回列表