Now you can Subscribe using RSS

Submit your Email

coprime number program

A LIFE ABK
coprime number program

In this program, we will discuss the program of co-prime numbers. What are co-prime numbers? How to make co-prime number program.

To understand this program, you must have this knowledge:

what is coprime number?

A set of numbers which do not any other common factor other than 1 are called co-prime numbers.

This means those numbers whose HCF is 1.

For example, 7 and 11 no other common factor other than 1 so they are coprime numbers.

if more information


Now, let us go to the program.


Source code: coprime number program



Output Screen

 
            Enter two number: 8
            6
            8,6 are not coprimes
            Enter two number:7
            11
            7,11 are coprimes
        

Program logic

First of all, we will take two inputs from the user. Then we will assign it to the variables namedaand b.

After that, we will apply the if-else condition. And will put the expression in the if condition or if the condition of a==b is true. So both these numbers are not coprime. If false. Then you will move on the else block.

In the body of else, we will use the conditional operator. Will check both of these. Which is the bigger number? Which is bigger. It will be assigned to a variable named big.

Then we will apply a loop. In which i will start the value from 2. And from i<big.

Inside the loop, we will apply the if condition. If that condition is true. So the break keyword goes. And move out of the cursor loop. And move to the next line. If the condition is not true. So the loop is complete. And then the next line has come.

Once again we will apply the if-else condition. And will check i==big. If there is. So a and b are coprime numbers.

If the value of i is not equal to big. So both numbers are not coprime.

Recomonded Post






😊

Now next you are, write your code in the comment below.😊

A LIFE ABK / Author & Editor

0 Comments:

Post a Comment

Please do not enter any spam link in the comment box.

Coprights @ 2021-2022, Ancient Code Designed By AbK