Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Write a shell program to find the gcd for the 2 given numbers

Posted By: Maddison Hughes     Category: Unix / Linux / Ubuntu     Views: 17689

Write a shell program to find the gcd for the 2 given
numbers

Code for Write a shell program to find the gcd for the 2 given numbers in Unix / Linux / Ubuntu

echo Enter two numbers with space in between
read a b
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
  
Share: 



Maddison Hughes
Maddison Hughes author of Write a shell program to find the gcd for the 2 given numbers is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!