#!/bin/bash
#累加
sum=0
number=0
echo "Enter the number(1+2+3+...number) :"
read NUM
while [ $number -le $NUM ]
do
sum=`expr $sum + $number`
number=`expr $number + 1`
done
echo "The sum is 1+2+3+...+$NUM = $sum"
运行如下:
[root@server while]# ./sum.sh
Enter the number(1+2+3+...number) :
100
The sum is 1+2+3+...+100 = 5050
:
阅读(943) | 评论(0) | 转发(0) |