Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

GCD OF

NUMBERS

-Madhusudhan
1 Introduction of gcd

2 Methods of Finding GCD

Inde
x
Introductio
n
The greatest common divisor (GCD) of two or more
numbers is the greatest common factor number that
divides them, exactly. It is also called the highest
common factor (HCF). For example, the greatest
common factor of 15 and 10 is 5
Methods of Finding
GCD of Numbers
using
C-programming
By Finding minimum of the given
numbers
General Method
Method By Finding Minimum of
1 Numbers
Step1 :- Start the algoritham
Step2:- Declare num1,num2,i,GCD,minimum
Step3:- Read num1,num2 value from the user
Step4:-compute min value by using
conditionaloperater
Step5:-initialise i=1
Step6:-Check if i less than or equal to min
if Step6 is true goto
Step6.1 else goto
Step7
Step6.1:- Check if num1%i is 0 and also num2%i is 0
if Step6.1 is true goto Step6.11 else
Step6.11:- Give i value to
GCD
Step6.2:-increase i value by 1 and
goto step6
Step7:-Display GCD
value
Step8:-Stop the
algorithm
Code:- #include <stdio.h>
void main()
{
int
num1,num2,i,
GCD,min;
scanf(“%d
%d”,&num1,&n
um2);
min=(num1<n
um2)?
num1:num2;
}
for(i=1;i<=min;
}
i++)
}
Method :-2 General
Algorithm: Method
-Step1:- Start the algorithm
Step2:- declare num1,num2,i,GCD.
Step3:- Read num1,num2 value from the
user
Step4:-initialise i=1
Step5:- check is i is less than or equal to num1
if Step5 is true goto step5.1 else goto
Step6
Step5.1:-Check if num1%i is 0 and also num2%i is
0
if Step5.1 is true goto Step5.11 else
goto5.2
Step5.11:-Give i value to GCD
Code:- #include <stdio.h>
void main()
{
int
num1,num2,i,
GCD,min;
scanf(“%d
%d”,&num1,&
num2);
for(i=1;i<=num
1;i++)
{
if(num1%i
==0 &&
Thank
You

You might also like