#include <iostream>
#include <cmath>
#include<cstdlib>
#define PI 3.14159
using namespace std;
int main()
{
double triangle , circle , rectangle ;
double a, b, r, e, f;
int c;
cout <<"若要計算三角形的面積,請輸入1" << endl;
cout <<"若要計算圓形的面積,請輸入2" << endl;
cout <<"若要計算矩形的面積,請輸入3" << endl;
cin >> c;
if (c==1){
cout<<"請輸入三角形的底和高"<<endl;
cin>> a,b;
triangle =a*b/2 ;
cout << triangle;
}
else if (c==2){
cin>>r;
cout <<"請輸入圓形的半徑"<< endl;
circle=r*r*PI;
cout <<"面積為"<< circle << endl;
}
else if (c==3){
cin>>e,f;
cout <<"請輸入長和寬"<<endl;
rectangle=e*f;
cout << "面積為"<< rectangle << endl;
}
system("pause");
return 0;
}
|