From b19b413b53b4a64da9ab64e30e6f4e117242dfee Mon Sep 17 00:00:00 2001 From: lilrax Date: Fri, 27 Feb 2026 14:36:48 +0300 Subject: [PATCH] Add GCD script (task 1) --- script_GCD.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 script_GCD.sh diff --git a/script_GCD.sh b/script_GCD.sh new file mode 100755 index 0000000..022f242 --- /dev/null +++ b/script_GCD.sh @@ -0,0 +1,25 @@ +#!/bin/bash + + +gcd() { + local a=$1 + local b=$2 + + while [ $b -ne 0 ]; do + local temp=$b + b=$((a % b)) + a=$temp + done + + echo $a +} + + +if [ $# -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + + +result=$(gcd $1 $2) +echo "НОД($1, $2) = $result"