search

Home  >  Q&A  >  body text

ubuntu - Unity数学问题:如何计算3位数的因子?

我正在写一个数学工具包,包括各种命令。其中一个命令是找出一个三位数的因子。把这个命名为“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

伊谢尔伦伊谢尔伦2908 days ago499

reply all(1)I'll reply

  • 迷茫

    迷茫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
    

    reply
    0
  • Cancelreply