专注各种脚本编程
Baidu
加入收藏夹
本站内容有下面分类知识,欢迎您的到来^_^
shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言 oracle
当前位置:| 主页>shell脚本欣赏>

用shell脚本读取其底边长和高计算一个三角形的面积

百度收藏 QQ搜藏

原文: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"
上一篇:shell脚本(功能:计算两个数的和并能够加减乘除) 下一篇:shell脚本实现X和Y两个数值的交换

power by soyo123 2007-2008