Loading…
OS · Loops & numbers · Program 10 · In the record
Write a shell script to print the GCD of the two input terms
1#!/bin/bash2 3echo "Enter the first number:"4read a5 6echo "Enter the second number:"7read b8 9x=$a10y=$b11 12while (( y != 0 ))13do14 r=$((x % y))15 x=$y16 y=$r17done18 19echo "GCD of $a and $b = $x"48 ⏎ 18Enter the first number: 48 Enter the second number: 18 GCD of 48 and 18 = 6
Run program 10 in your browser
bash · just-bash. Change the code or the input, run it, break it, and see what happens.