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