Add GCD, LCM and main scripts
This commit is contained in:
22
script_LCM.sh
Executable file
22
script_LCM.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
# script_LCM.sh
|
||||
|
||||
gcd() {
|
||||
a=$1
|
||||
b=$2
|
||||
while [ $b -ne 0 ]; do
|
||||
temp=$b
|
||||
b=$((a % b))
|
||||
a=$temp
|
||||
done
|
||||
echo $a
|
||||
}
|
||||
|
||||
lcm() {
|
||||
a=$1
|
||||
b=$2
|
||||
gcd_val=$(gcd $a $b)
|
||||
echo $((a * b / gcd_val))
|
||||
}
|
||||
|
||||
lcm $1 $2
|
||||
Reference in New Issue
Block a user