10.8 C高级-shell脚本3

1、思维导图:

2、练习 

分支结构结合test指令完成一下编程

1>判断闰年

2>输入一个数判断是否为偶数

3>使用test指令实现等级判断 90--100A 60--89B 0-50C 其他错误

代码:
#!/bin/bash
#分支结构结合test指令完成以下编程
#1判断是否闰年
read -p "请输入年份:" year
if [ $((year%4)) -eq 0 -a $((year%100)) -ne 0 -o $((year%400)) -eq 0 ]
then
	echo $year年是闰年
else
	echo $year年是平年
fi

#2输入一个数判断是否为偶数
read -p "请输入一个数:" num
if [ $((num%2)) -eq 0 ]
then
	echo $num值为偶数
else
	echo $num值为奇数
fi

#3使用test指令实现等级判断90-100为A 60-89为B 0-59为C,其他为错误
read -p "请输入成绩:" score
if test $score -ge 90 -a $score -lt 100 
then
	echo $score分等级为A
elif [ $score -ge 60 -a $score -lt 90 ]
then
	echo $score分等级为B
elif [ $score -ge 0 -a $score -le 59 ]
then
	echo $score分等级为C
else
	echo "输入错误!"
fi
代码结果: 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值