試寫ㄧ程式,可計算梯形面積或三角形面積.選擇計算梯形面積時,會要求輸入上底,下底,高;選擇計算三角形面積時,會要求輸入底,高.
請問要怎麼打出分成三角形跟梯形
可以請各位大大給我範例或是意見嗎!!?
2007-12-15 11:50:10 · 1 個解答 · 發問者 泫淏 1 in 電腦與網際網路 ➔ 程式設計
//Power by Visual Studio 2005
//Download Site: http://www.microsoft.com/taiwan/vstudio/express/
#include
#include
int main(int argc, char* argv[]){
//=====START=====//
char opt[2];
double f,h,c;
printf("Counting Area...\n1.Triangle\n2.Trapezoid\nOptions(1/2):"),scanf("%s",opt);
switch(opt[0]){
case '1':
printf("Input the Floor of Triangle: "),scanf("%lf",&f);
printf("Input the Height of Triangle: "),scanf("%lf",&h);
printf("The Area of Triangle= %lf\n ",f*h/2);
break;
case '2':
printf("Input the Ceil of Trapezoid: "),scanf("%lf",&c);
printf("Input the Floor of Triangle: "),scanf("%lf",&f);
printf("Input the Height of Trapezoid: "),scanf("%lf",&h);
printf("The Area of Trapezoid= %lf\n ",(c+f)*h/2);
break;
default:
break;
}
//=====END=====//
system("PAUSE");
return 0;
}
2007-12-15 14:37:10 · answer #1 · answered by Big_John-tw 7 · 0⤊ 0⤋