Merge pull request 'Add LCM script and update main' (#1) from feature-lcm into main
Reviewed-on: #1
This commit is contained in:
4
main.sh
4
main.sh
@@ -7,6 +7,8 @@ read num1
|
|||||||
|
|
||||||
echo "pls write second agr"
|
echo "pls write second agr"
|
||||||
read num2
|
read num2
|
||||||
gcd=$(./script_GCD.sh $num1 $num2)
|
gcd=$(bash ./script_GCD.sh $num1 $num2)
|
||||||
|
LCM=$(bash ./script_LCM.sh $num1 $num2)
|
||||||
|
|
||||||
echo "GCD for $num1 and $num2 is $gcd"
|
echo "GCD for $num1 and $num2 is $gcd"
|
||||||
|
echo "LCM for $num1 and $num2 is $LCM"
|
||||||
|
|||||||
18
script_LCM.sh
Executable file
18
script_LCM.sh
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ $# -ne 2 ]; then
|
||||||
|
echo "error, pls write 2 arguments"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
a=$1
|
||||||
|
b=$2
|
||||||
|
|
||||||
|
GCD=$(bash ./script_GCD.sh $a $b | head -n1)
|
||||||
|
|
||||||
|
if ! [[ "$GCD" =~ ^[0-9]+$ ]]; then
|
||||||
|
echo "Error"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $(( ($a * $b) / $GCD ))
|
||||||
Reference in New Issue
Block a user