•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 457,640 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,779 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 1102 | Replies: 6
![]() |
•
•
Join Date: Apr 2008
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
I got a program to find the GCD of 2 numbers. But i need the program to find the GCD of three numbers.
Program to find the GCD of 2 numbers is as follows
So please write a program to find the GCD of 3 numbers.
Program to find the GCD of 2 numbers is as follows
•
•
•
•
echo "Enter first number"
read n1
echo "Enter the second number"
read n2
gcd=0
if test $n1 -gt $n2
then
i=1
while test $i -le $n1
do
a=`expr $n1 % $i`
b=`expr $n2 % $i`
if test $a -eq 0 -a $b -eq 0
then
if test $gcd -lt $i
then
gcd=$i
fi
fi
i=`expr $i + 1`
done
fi
if test $n2 -gt $n1
then
i=1
while test $i -le $n2
do
a=`expr $n1 % $i`
b=`expr $n2 % $i`
if test $a -eq 0 -a $b -eq 0
then
if test $gcd -lt $i
then
gcd=$i
fi
fi
i=`expr $i + 1`
done
fi
echo GCD of $n1 and $n2 = $gcd
So please write a program to find the GCD of 3 numbers.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Shell Scripting Forum
- Previous Thread: Shell script accepting input from a pipe AND the keyboard
- Next Thread: How to bulk resize JPG files in folder and subfolder



Linear Mode