[4734 views]

Co-prime numbers are the numbers that have only 1 as a common factor between them. In other words, the highest common factor of the numbers will always be 1. They are also known as mutually prime or relatively prime numbers. For example: (3,5), (14,15), (11,13), (2,7), etc.

Let us consider the example of 5,6:

Factors of 5: 1,5.

Factors of 6: 1, 2, 3, 6.

Common factors: 1

Therefore, 5 and 6 are co-prime.

It is important to note that it is not necessary that both the numbers have to be prime in a co-prime number pair. For example: (2,9), (2,15), (4,13), (4,15), etc. Here, in each pair of numbers, there is one prime and one non-prime number.

In this article, we will learn how to check whether two given numbers are coprime numbers or not, with the help of an algorithm and flowchart. In this algorithm, we will use the concept of HCF to find out the common factors between the given numbers.

In this algorithm, we need to check whether two given numbers are co-prime or not. To do so, we need to find out the common factors between the two numbers. Here, we use the concept of HCF. Two numbers are co-prime if their HCF is equal to 1. We apply this concept to our algorithm.

The algorithm starts off by taking the two numbers to be checked as user input. We store these values into two variables: say n1 and n2. We initialize the HCF of the two numbers as 1. To calculate the HCF, we start a loop that runs from 1 until loop variable is greater than n1 or n2, whichever is smaller. In each iteration, we check whether i is divisible by n1 as well as n2. If both the numbers are divisible by i, this means there is a common factor between the numbers. HCF will then become that common factor. We exit from the loop and check whether the hcf is equal to one or not. If it is one, we display "co-prime numbers", else, we display "not co-prime numbers".

- Java IDE Online
- Python IDE Online
- JSON Formatter/Minifier Online
- Case Converter
- Reverse String
- HTML Encoder
- HTML Decoder
- URL Encoder
- URL Decoder
- Decimal To Binary
- Binary To Decimal
- Decimal To Octal
- Binary To Octal
- Decimal To Hexadecimal
- Hexadecimal To Decimal
- Hexadecimal To Binary
- Octal To Decimal
- Octal to Hexadecimal
- Octal to Binary
- Calculate String Length
- Remove Spaces
- Remove Line Breaks
- Remove Empty Lines
- Remove Duplicate Lines
- Word Counter
- Replace Space with hyphen
- Check Armstrong number
- Text to URL

- Algorithm and Flowchart to Find Area and Circumference of Circle
- Prefix to Infix notation Algorithm and Flowchart
- Algorithm and Flowchart to represent a number as sum of two prime numbers
- Algorithm and Flowchart to convert temperature from Celsius to Fahrenheit
- Pseudocode and flowchart to find the series of S= 1 - 3 + 5 - 7 + 9