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

shell脚本之简单计算圆的周长和面积

百度收藏 QQ搜藏

原文:http://bash.cyberciti.biz/shell-math/calulate-area-circumference-of-circle/

圆的命名


以下是该shell脚本的源代码:Sample Shell Script

#!/bin/bash
# Shell script to calulate area and Circumference of circle.
# It take radius of a circle as input.
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# ----------------------------------------------------------------------
# Lesson on Circumference of a Circle :
#  Visit http://www.mathgoodies.com/lessons/vol2/circumference.html
echo -n "Enter the radius of a circle : "
read r
 
# use formula to get it
area=$(echo "scale=2;3.14 * ($r * $r)" | bc)
 
# use formula to get it
d=$(echo "scale=2;2 * $r"|bc)
circumference=$(echo "scale=2;3.14 * $d"| bc)
 
echo "Area of circle is $area"
echo "Circumference of circle is $circumference"
上一篇:用shell脚本计算用户输入的5位的数字的各位数的和 下一篇:模拟密码验证的shell脚本

power by soyo123 2007-2008