shell脚本借助循环求1-100的和
发布时间:2021-11-22 09:36:16 所属栏目:PHP教程 来源:互联网
导读:shell脚本利用循环求1-100的和 利用while循环: #!/bin/bash total=0 num=0 while ((num = 100)); do total=`expr $total + $num` num=$num + 1 done echo $total ~ 或者 #!/bin/bash i=0 n=0 while [ $i -le 100 ] ;do let n=$n+$i let i=$i+1 done echo $n
shell脚本利用循环求1-100的和 利用while循环: #!/bin/bash total=0 num=0 while ((num <= 100)); do total=`expr $total + $num` num="$num + 1" done echo "$total" ~ 或者 #!/bin/bash i=0 n=0 while [ $i -le 100 ] ;do let n=$n+$i let i=$i+1 done echo $n 利用for循环求和: #!/bin/bash total=0 for ((j=1;j<=100;j++)); do total=`expr $total + $j` done echo "The result is $total" ![]() (编辑:应用网_丽江站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐
热点阅读