1 Commits

Author SHA1 Message Date
lilrax
f1707d4691 Add LCM script (Task 2) 2026-03-14 22:18:56 +03:00
4 changed files with 3 additions and 35 deletions

View File

@@ -1 +0,0 @@
# Lab Git

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Function to find GCD using Euclidean algorithm
gcd() { gcd() {
local a=$1 local a=$1
local b=$2 local b=$2
@@ -14,12 +14,12 @@ gcd() {
echo $a echo $a
} }
# Check arguments
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
echo "Usage: $0 <number1> <number2>" echo "Usage: $0 <number1> <number2>"
exit 1 exit 1
fi fi
# Call function and print result
result=$(gcd $1 $2) result=$(gcd $1 $2)
echo "НОД($1, $2) = $result" echo "НОД($1, $2) = $result"

0
script_LCM.sh Normal file → Executable file
View File

View File

@@ -1,31 +0,0 @@
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "=== Калькулятор НОД и НОК ==="
echo ""
read -p "Введите первое число: " num1
read -p "Введите второе число: " num2
if ! [[ "$num1" =~ ^[0-9]+$ ]] || ! [[ "$num2" =~ ^[0-9]+$ ]]; then
echo "Ошибка: введите целые положительные числа!"
exit 1
fi
echo ""
echo "Результаты:"
echo "-----------"
echo -n "НОД: "
bash "$SCRIPT_DIR/script_GCD.sh" "$num1" "$num2"
echo -n "НОК: "
bash "$SCRIPT_DIR/script_LCM.sh" "$num1" "$num2"