Files
repo2/script_GCD.sh
2026-02-28 15:13:16 +03:00

26 lines
591 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
a=$1
b=$2
# Алгоритм Евклида
while [ $b -ne 0 ]; do
remainder=$((a % b))
a=$b
b=$remainder
done
echo $a