- #include<cstdlib>
- #include<iostream>
- #include<Math.h>
- using namespace std;
- int main()
- {
- int m;
- float a,b;
- cout<<"請選擇圖形:1.圓形 2.三角形"<<endl;
- cin>>m;
- switch(m)
- {
- case 1:
- cout<<"請輸入圓形的半徑:";
- cin>>a;
- cout<<"此圓形的面積為:"<<(a*a*M_PI)<<endl;
- break;
- case 2:
- cout<<"請輸入三角形的高:";
- cin>>a;
- cout<<"請輸入三角形的底:";
- cin>>b;
- cout<<"此三角形的面積為:"<<(a*b)/2<<endl;
- break;
- default:
- cout<<"ERROR!ERROR!"<<endl;
- break;
- }
- system("pause");
- return 0;
- }
複製代碼 |