Files
.todo_lini/script_nod.sh

33 lines
855 B
Bash
Executable File
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.

#!/bin/bash
# Проверка количества аргументов
if [ $# -ne 2 ]; then
echo "Использование: $0 <число1> <число2>"
exit 1
fi
# Проверка, что аргументы являются числами
if ! [[ "$1" =~ ^[0-9]+$ ]] || ! [[ "$2" =~ ^[0-9]+$ ]]; then
echo "Ошибка: аргументы должны быть целыми неотрицательными числами"
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
}
# Вычисление НОД
result=$(gcd $1 $2)
echo "Наибольший общий делитель (НОД) чисел $1 и $2 = $result"