A Shell program To Find The GCD | Linux
The given problem asked in fico placement interview round. Find the gcd of two given numbers using shell scripting
We are given two numbers A and B and now task is to find the Greatest Common divisor (gcd) of two given number using shell scripting .
Asked in interview : FICO
Input 25 15 Output 5
The shell script for the above code is :
echo Enter two numbers with space in between read a b //reads numbers m=$a if [ $b -lt $m ] then m=$b fi while [ $m -ne 0 ] do x=`expr $a % $m` y=`expr $b % $m` if [ $x -eq 0 -a $y -eq 0 ] then echo gcd of $a and $b is $m break fi m=`expr $m - 1` done
This article is contributed by Ajay Puri. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.