我正在写一个数学工具包,包括各种命令。其中一个命令是找出一个三位数的因子。把这个命名为“myfactors”。这是示例
$ myfactors abc
abc is not a number. Please enter a number
$ myfactor 72
72 is not a 3 digit number
$ myfactor 105
The factors are: 1 3 5 7 15 21 35 105
原问题:How to find the factors of a 3 digit number
迷茫2017-04-21 10:57:49
Answer:
Nischay
Take a look at this, factor GNU tools available in Ubuntu.
#!/bin/bash
num=
if [ "$num" -ge 100 ]
then
factor="`factor $num`"
echo "Factor of number $num is $factor"
else
echo "Enter number is not a 3 digit number"
fi
Or you can strictly limit it to only accept 3 digits.
#!/bin/bash
num=
if [ "$num" -ge 100 ] && [ "$num" -lt 1000 ]
then
factor="`factor $num`"
echo "Factor of number $num is $factor"
else
echo "Enter number is not a 3 digit number"
fi