Knowee
Questions
Features
Study Tools

Write an algorithm and draw a flowchart to find greatest common divisor and smallest common divisor of two given positive number.

Question

Write an algorithm and draw a flowchart to find greatest common divisor and smallest common divisor of two given positive number.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is the algorithm to find the greatest common divisor (GCD) and least common multiple (LCM) of two given positive numbers. Please note that the smallest common divisor of any two positive numbers is always 1, so we don't need to find that. The LCM is considered as the smallest common multiple, not divisor.

Algorithm:

  1. Start
  2. Input the two numbers, num1 and num2.
  3. Set a variable gcd to 1.
  4. For i from 1 to the minimum of num1 and num2,
    • If num1 and num2 are both divisible by i, set gcd to i.
  5. Print gcd as the greatest common divisor.
  6. Calculate lcm as (num1*num2)/gcd.
  7. Print lcm as the least common multiple.
  8. End

Flowchart:

  1. Start
  2. Input num1, num2
  3. Initialize gcd = 1
  4. For i = 1 to min(num1, num2)
  5. Is num1 mod i == 0 and num2 mod i == 0?
  6. ↓ Yes → Update gcd = i, No → Continue loop
  7. End of loop
  8. Print gcd
  9. Calculate lcm = (num1*num2)/gcd
  10. Print lcm
  11. End

Please note that this is a simple algorithm and flowchart. There are more efficient algorithms available for finding GCD and LCM, such as the Euclidean algorithm.

This problem has been solved

Similar Questions

Flowchart for finding the greatest of three numbers in python

Draw a flowchart to find smallest of the three numbers entered by User

Write a program to find out the Highest Common Factor for given two numbers.

Write a pseudo code + Draw Flowchart that find the biggest of three (3) Numbers

Develop a Java program to find the GCD (Greatest Common Divisor) of two numbers.Input FormatTwo integers a and b separated by a space.ConstraintsThe absolute values of a and b will be less than or equal to 10^9. a and b are non-negative integers.Output FormatA single integer representing the GCD of a and b.Sample Input 012 18Sample Output 06Contest ends in an hourSubmissions: 0Max Score: 5Difficulty: EasyRate This Challenge: More Java 151import java.io.*;2import java.util.*;3​4public class Solution {5​6    public static void main(String[] args) {7        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */8   }9}

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.