Files
Adonev_Bublik/script_LCM.sh
2026-02-14 19:51:09 +03:00

29 lines
524 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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