本帖最後由 李泳霖 於 2024-11-9 16:03 編輯
利用自訂函式, 建立計算各種圖形面積的程式.




 - #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- void q1()
- {
- double a,b;
- cout<<"請輸入三角形的底:";
- cin>>a;
- cout<<"請輸入三角形的高:";
- cin>>b;
- cout<<"三角形的面積為"<<a*b/2<<"平方公分"<<endl;
- }
- int main()
- {
- int a;
- cout<<"要計算哪一種形狀的面積? (1)三角形 (2)圓形 (3)矩形 (4)梯形"<<endl;
- cin>>a;
- if(a==1)
- q1();
- return 0;
- }
複製代碼
|