早教吧 育儿知识 作业答案 考试题库 百科 知识分享

linux-shell编程1.根据不同的分数段,输出不同的级别(如60及格,70-80中,80-90良,90-100优,60分以下不及格)2.输出1...10的平方3.输出1...100中能被5整除的数。

题目详情
linux-shell 编程
1.根据不同的分数段,输出不同的级别(如60及格,70-80中,80-90良,90-100优,60分以下不及格)
2.输出1...10的平方
3.输出1...100中能被5整除的数。
▼优质解答
答案和解析
(1)
#!/bin/bash
#如60及格,70-80中,80-90良,90-100优,60分以下不及格
while true
do
echo -n "input scores: "
read score
if [ $score = "q" ]
then exit
fi
if [ $score -lt 60 ]
then
echo "不及格"
elif [ $score -eq 60 ]
then
echo "及格"
elif [ $score -ge 70 -a $score -lt 80 ]
then echo "中"
elif [ $score -ge 80 -a $score -lt 90 ]
then echo "良"
elif [ $score -ge 90 -a $score -lt 100 ]
then echo "优"
fi
done
(2)
#!/bin/bash
# 输出1...10的平方
for n in 1 2 3 4 5 6 7 8 9 10
do
echo -n $(($n*$n))
echo -n " "
done
echo ""
(3)
#!/bin/bash
#输出1...100中能被5整除的数
for i in {1..100}
do
if [ $(($i%5)) -eq 0 ]
then echo $i
fi
done