原文:http://bash.cyberciti.biz/shell-math/calculate-area-of-triangle/ 计算一个三角形的面积是我们在小学就有遇到的问题,往往有许多不同的情况,而最知名,最简单的三角形面积公式是
s=1/2bh
其中s为三角形面积,b为三角形底边长,h为三角形的高,现在我们用shell脚本来解决这个基本公式。
以下是该shell脚本的源代码:
# Shell program/script to read the base and height of a traingle and find its area
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# Formula info: http://www.mste.uiuc.edu/dildine/heron/triarea.html
# Area=(1/2) x Base x Height
echo -n "Enter base of a triangle : "
read b
echo -n "Enter height of a triangle : "
read h
# calculate it and display back
area=$(echo "scale=2;(1/2) * $b * $h"|bc)
echo "Area of a triangle is $area" |