Compare commits
1 Commits
feature/gc
...
aad3bdba1e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aad3bdba1e |
@@ -1,35 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Function to find GCD (Greatest Common Divisor)
|
|
||||||
gcd() {
|
|
||||||
local a=$1
|
|
||||||
local b=$2
|
|
||||||
|
|
||||||
while [ $b -ne 0 ]; do
|
|
||||||
local temp=$b
|
|
||||||
b=$((a % b))
|
|
||||||
a=$temp
|
|
||||||
done
|
|
||||||
|
|
||||||
echo $a
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to find LCM (Least Common Multiple)
|
|
||||||
lcm() {
|
|
||||||
local a=$1
|
|
||||||
local b=$2
|
|
||||||
|
|
||||||
# LCM = (a * b) / GCD(a, b)
|
|
||||||
local gcd_value=$(gcd $a $b)
|
|
||||||
echo $(( (a * b) / gcd_value ))
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check arguments
|
|
||||||
if [ $# -ne 2 ]; then
|
|
||||||
echo "Usage: $0 <number1> <number2>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Call function and print result
|
|
||||||
result=$(lcm $1 $2)
|
|
||||||
echo "НОК($1, $2) = $result"
|
|
||||||
Reference in New Issue
Block a user