Add GCD, LCM and main scripts

This commit is contained in:
24_NikitinaEA
2026-02-27 19:40:19 +00:00
parent 5c18bdb164
commit ca9937d5cd
3 changed files with 47 additions and 0 deletions

10
main.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
# main.sh
echo "Введите первое число:"
read num1
echo "Введите второе число:"
read num2
echo "НОД($num1, $num2) = $(./script_GCD.sh $num1 $num2)"
echo "НОК($num1, $num2) = $(./script_LCM.sh $num1 $num2)"

15
script_GCD.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
# script_GCD.sh
gcd() {
a=$1
b=$2
while [ $b -ne 0 ]; do
temp=$b
b=$((a % b))
a=$temp
done
echo $a
}
gcd $1 $2

22
script_LCM.sh Executable file
View 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