7 Commits

Author SHA1 Message Date
lilrax
82a0a158eb Add LCM script (Task 2) - final 2026-03-14 22:58:32 +03:00
8a63684eff Merge pull request 'Add GCD script (Task 1)' (#4) from feature/gcd-task1 into master
Reviewed-on: #4
2026-03-14 22:34:03 +03:00
336710739c Merge pull request 'Add main script (Task 3)' (#5) from feature/main-script into master
Reviewed-on: #5
2026-03-14 22:33:51 +03:00
lilrax
1970118dba Add main script (Task 3) 2026-02-27 16:36:07 +03:00
lilrax
8d4c3ee399 Add GCD script (Task 1) 2026-02-27 16:12:26 +03:00
lilrax
243e24255c Add main script (task 3) 2026-02-27 14:54:16 +03:00
lilrax
aad3bdba1e Initial commit 2026-02-27 14:43:19 +03:00
4 changed files with 70 additions and 3 deletions

1
README.md Normal file
View File

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

View File

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

35
script_LCM.sh Normal file
View File

@@ -0,0 +1,35 @@
#!/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"

31
script_main.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/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"