forked from 24_ZhurovichAM/lab_git
Compare commits
2 Commits
feature/ma
...
feature/lc
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cd515b428 | |||
|
|
bfd0168b25 |
17
script_LCM.sh
Executable file
17
script_LCM.sh
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
gcd() {
|
||||||
|
local a=$1 b=$2
|
||||||
|
while [ $b -ne 0 ]; do
|
||||||
|
local temp=$b; b=$((a % b)); a=$temp
|
||||||
|
done
|
||||||
|
echo $a
|
||||||
|
}
|
||||||
|
lcm() {
|
||||||
|
local a=$1 b=$2
|
||||||
|
local g=$(gcd $a $b)
|
||||||
|
echo $(( (a * b) / g ))
|
||||||
|
}
|
||||||
|
if [ $# -ne 2 ]; then
|
||||||
|
echo "Usage: $0 <num1> <num2>"; exit 1
|
||||||
|
fi
|
||||||
|
echo "НОК($1, $2) = $(lcm $1 $2)"
|
||||||
Reference in New Issue
Block a user