Important Notice:

GCD (Greatest Common Divisor) of Two Numbers

GCD (Greatest Common Divisor) of Two Numbers

2 views 1 min read
GCD (Greatest Common Divisor) of Two Numbers :- Question

Write an algorithm and flowchart to find the GCD (Greatest Common Divisor) of two numbers.

दो संख्याओं का GCD (Greatest Common Divisor / महत्तम समापवर्तक) ज्ञात करने के लिए एक Algorithm और Flowchart लिखिए।

Example

Input: A = 24, B = 36
GCD: 12

Algorithm
  1. Start.
  2. Input two numbers A and B.
  3. If B ≠ 0, set TEMP = A % B.
  4. Set A = B.
  5. Set B = TEMP.
  6. Repeat Steps 3 to 5 while B ≠ 0.
  7. Display A as the GCD.
  8. Stop.
Logic -

TEMP = A % B
A = B
B = TEMP

Repeat until B = 0.

When B becomes 0, the value of A is the GCD.

Flowchart :-

 
 
 
 

Related Notes