導航:首頁 > 源碼編譯 > 三角邊長演算法軟體

三角邊長演算法軟體

發布時間:2023-08-19 02:58:52

編程題:編寫程序輸入三角形的3條邊長,計算並輸出三角形的面積。

一、程序分析

三角形面積海倫公式:√[ p ( p - a ) ( p - b ) ( p - c ) ] 。其中 p = (a + b + c) / 2 。a、b、c分別是三角形的三邊長。

二、根據三角形面積計算公式用if語句編寫程序如下:

#include "stdio.h"

#include "math.h"

int main(void)

{

float a = 0, b = 0, c = 0, p = 0;

float area = 0;

printf("Please input three sides of triangle:");

scanf_s("%f %f %f", &a, &b, &c);

if((a + b) > c && (a + c) > b && (b + c) > a)

{

p = (a + b + c) / 2;

area = sqrt(p * (p - a) * (p - b) * (p - c));

}

else

printf("Triangle does not exist! ");

printf("The area of triangle is:%f ", area);

return 0;

(1)三角邊長演算法軟體擴展閱讀:

還可以使用switch語句計算三角形的面積,編寫程序如下

#include "stdio.h"

#include "math.h"

int main(void)

{

float a = 0, b = 0, c = 0;

float p = 0;

printf("Please input three sides of triangle:");

scanf_s("%f %f %f", &a, &b, &c);

switch (a + b > c && a + c > b && b + c > a)

{

case 0:printf("Triangle does not exist! "); break;

case 1:

p = (a + b + c)*0.5;

printf("The area of triangle is:%f ", sqrt(p * (p - a) * (p - b) * (p - c)));

break;

}

return 0;

}

閱讀全文

與三角邊長演算法軟體相關的資料

熱點內容
君威壓縮機電磁閥 瀏覽:945
安卓6手機為什麼不能用app 瀏覽:860
什麼java編譯器支持中文 瀏覽:563
香港伺服器如何做代理 瀏覽:201
pdf寫入 瀏覽:986
高爾夫電台怎麼添加到文件夾 瀏覽:239
四川麻將一般下哪個app 瀏覽:864
反編譯exe腳本 瀏覽:462
源碼文件夾怎麼編譯到固件中 瀏覽:912
ERp列印伺服器錯誤怎麼弄 瀏覽:113
蚌埠u盤加密軟體有哪些 瀏覽:180
前端如何認證伺服器 瀏覽:556
linux切換db2用戶命令 瀏覽:308
相片如何用電解壓 瀏覽:908
碩士程序員去學校當老師 瀏覽:122
pythonstr提取到字典 瀏覽:820
程序員那麼可愛有人看上陸漓了 瀏覽:878
php正則提取圖片 瀏覽:105
pythonlinuxdjango 瀏覽:565
php中文返回亂碼 瀏覽:91