Merge pull request 'Add GCD, LCM and main scripts' (#1) from feature/gcd-lcm-scripts into master

Reviewed-on: 24_NikitinaEA/-----------#1
This commit is contained in:
2026-02-27 22:50:20 +03:00
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