10、编写脚本提示用户输入一个正整数,程序将输出信息提示该正整数是否为质数,(提示只有2是质数,如果为奇数,且不能被任何一个小于或者等于它平方根的奇数整除,那么该奇数就是质数。)
11、一个数恰好等于它的因子之和,这样的数称为“完数”。例如,6的因子为1,2,3,而6=1+2+3,因此,6是“完数”。编写程序写出1000以内所有的完数,并按下面的格式 输出其因子:
6 its factors are 1 2 3
12、编写一个脚本读入一些整数,分别输入 出这些整数中的奇数的个数和偶数的个数,并输出0的个数;
13、编写一个脚本提示用户输入一个整数,程序将分别输出该整数第个位上的数字,并输出这些数字的和,例如,输出整数2345第个位上的2345;输出-3456第个位上的数字是3456;
14、使用while循环编写脚本,使其他完成下面的功能;
1)提示用户输入两个整数:firstNum和secondNum(firstNum的值一定要小于secondNum)。
2)输出所有介于firstNum和secondNum之间的奇数。
3)输出所有介于firstNum和secondNum之间的偶数之和。
#!/bin/bash
#
echo "Please input two number:(The first number is greater than the second number)"
read firstNum secondNum
nums=`echo $firstNum $secondNum | wc -w`
signal=0
if [ -n $firstNum ]; then
echo "$firstNum"
else
echo "Please input firstNum:"
read firstNum
fi
if [ -n "$secondNum" ]; then
echo "$secondNum"
else
echo "Please input secondNum:"
read secondNum
fi
while (( signal != 1 ))
do
if [ "$nums" != 2 ]; then
echo "Please input two number:"
read firstNum secondNum
if [ "$firstNum" -lt "$secondNum" ]; then
echo "Please input two number:(The first number is greater than the second number"
read firstNum secondNum
else
signal=1
echo "$firstNum" is greater than "$secondNum"
fi
else
signal=1
echo "$firstNum" is greater than "$secondNum"
fi
done
15、分别使用until循环和for循环改写习题14
16、将习题7的图案的脚本加入break和continue循环控制符,查询显示的结果?
17、上机运行下面的脚本,查看脚本的输出结果是什么?
