返回列表 發帖
  1. #include<cstdlib>
  2. #include<iostream>
  3. #include<Math.h>
  4. using namespace std;

  5. int main()
  6. {
  7.     cout<<"PI:"<<M_PI;
  8.     float a,b;
  9.     int mode;
  10.     cout<<"請選擇想計算的面積(1)三角形(2)圓形"<<endl;
  11.     cin>>mode;
  12.    
  13.     switch(mode)
  14.     {
  15.     case 1:
  16.     cout<<"請輸入三角形的高:";
  17.     cin>>a;
  18.     cout<<"請輸入三角形的底:";
  19.     cin>>b;
  20.     cout<<"此三角形的面積為:"<<(a*b)/2<<endl;
  21.          break;
  22.     case 2:
  23.     cout<<"請輸入圓形的半徑"<<endl;
  24.     cin>>a;
  25.    
  26.     cout<<"面積為:"<<(a*a)*3.14<<endl;
  27.          break;
  28.     default:
  29.             cout<<"Error請重新輸入"<<endl;
  30.     }
  31.    
  32.     system("pause");
  33.     return 0;
  34. }
複製代碼

TOP

返回列表