首页 > 代码库 > shell脚本,计算输入给定的数,判断最大值,最小值,总和?
shell脚本,计算输入给定的数,判断最大值,最小值,总和?
[root@localhost ~]# cat five.sh #!/bin/bash#任意输入5个数,判断最大值,最小值,总和s=0read -p "please input:" nums=$(($s+$num))max=$nummin=$numfor i in `seq 4`do read -p "please input:" num s=$(($s+$num)) if [ $num -le $min ];then min=$num fi if [ $num -ge $max ];then max=$num fidoneecho sum:$s max:$max min:$min[root@localhost ~]# bash five.sh please input:30please input:20please input:40please input:10please input:0sum:100 max:40 min:0
[root@localhost ~]# cat 2five.sh #!/bin/bash#任意输入3个数,判断最大值,最小值,总和s=0n=0for i in `seq 3`do read -p "please input:" num expr ${num} + 0 1>/dev/null 2>&1 if [ $? -eq 0 ];then echo "${num} is a number!" else echo "${num} is not a number!" exit fi s=$(($s+$num)) [ $n -eq 0 ] && max=$num && min=$num n=$(($n+1)) if [ $num -le $min ];then min=$num fi if [ $num -ge $max ];then max=$num fidoneecho sum:$s max:$max min:$min n:$n[root@localhost ~]# bash 2five.sh please input:4040 is a number!please input:2020 is a number!please input:1010 is a number!sum:70 max:40 min:10 n:3[root@localhost ~]#
shell脚本,计算输入给定的数,判断最大值,最小值,总和?
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。