LCM script by Aleksandr
This commit is contained in:
28
script_LCM.sh
Normal file
28
script_LCM.sh
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
GNU nano 7.2 script_LCM.sh
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ $# -ne 2 ]; then
|
||||||
|
echo "Использование: $0 <число1> <число2>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
gcd() {
|
||||||
|
local a=$1
|
||||||
|
local b=$2
|
||||||
|
while [ $b -ne 0 ]; do
|
||||||
|
local temp=$b
|
||||||
|
b=$((a % b))
|
||||||
|
a=$temp
|
||||||
|
done
|
||||||
|
echo $a
|
||||||
|
}
|
||||||
|
|
||||||
|
lcm() {
|
||||||
|
local a=$1
|
||||||
|
local b=$2
|
||||||
|
local gcd_val=$(gcd $a $b)
|
||||||
|
echo $((a * b / gcd_val))
|
||||||
|
}
|
||||||
|
|
||||||
|
result=$(lcm $1 $2)
|
||||||
|
echo $result
|
||||||
Reference in New Issue
Block a user