Algorithm and flowchart to check two numbers are Amicable number or not

[2708 views]




What are Amicable numbers?

Two numbers are said to be amicable numbers if the sum of the divisor of each number is equal to the other number. For example: 220 and 284, 1184 and 1210, 2620 and 2924, etc.

Let us consider the example of 220 and 284.
Divisors of 220: 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110
Sum of divisors: 1+2+4+5+10+11+20+22+44+55+110 = 284
Divisors of 284: 1, 2, 7, 71, 142
Sum of divisors: 1+2+7+71+142 = 220
Therefore, as 220 and 284 are the equal the sum of divisors of each other, they are an amicable number pair.

In this article, we will learn how to check whether two given numbers are an amicable pair or not, with the help of an algorithm and flowchart.

Algorithm to check two numbers are Amicable number or not:

Step 1: Start Step 2: Read the first number to be checked as user input: n1 Step 3: Read the second number to be checked as user input: n2 Step 4: Initialize the sum of divisors of first number as zero Step 5: Initialize the sum of divisors of second number as zero Step 6: FOR i = 1 to n1 DO: 6.1: IF n1 % i = 0, THEN: sum_n1 = sum_n1 + i 6.2: END IF Step 7: END FOR Step 8: FOR i = 1 to n2 DO: 8.1: IF n2 % i = 0, THEN: sum_n2 = sum_n2 + i 8.2: END IF Step 9: END FOR Step 10: IF sum_n1 = n2 AND sum_n2 = n1, THEN: 10.1: Display “Amicable Number” Step 11: ELSE 11.1: Display “Not Amicable number” Step 12: END IF-ELSE Step 13: Stop

Explanation:

In this algorithm, we need to check whether two given numbers are amicable numbers or not. To do so, we need to find out all the divisors of each number and then find out the sum of those divisors separately. If the sum of divisors is equal to the other number, it is an amicable number pair.

We start the algorithm by taking the two numbers to be checked as user input. We store these numbers in two variables, say n1 and n2. We then initialize the sum of divisors of these numbers as 0, which will be used later. Now, we must find out the divisor of each of the two numbers and then find out the sum accordingly. To do so, we start a loop that runs from 1 to n1. In each iteration of this loop, we check whether n1 is divisible by the loop variable i or not. If it is divisible, then i is a divisor of n1. So, we add i to the sum of divisors of the first number, which was initialized earlier.

Once this loop terminates, we repeat the same process for n2. After we get both the sums, we check whether sum_n1 and sum_n2 are equal or not. If it is equal, the given pair is amicable. Else, it is not amicable. The appropriate message is displayed.

Flowchart to check two numbers are Amicable number or not:

Algorithm and flowchart to check two numbers are amicable number or not
Remove WaterMark from Above Flowchart

                 



Want to Learn How to write own Algorithm and Flowcharts



Want to test your logical skills in Algorithms?




Comments










Search Anything:

Sponsored Deals ends in





Technical Quizzes Specially For You:

Search Tags

    Amicable Number checker Algorithm

    Amicable Number Verifier Pseudocode

    Flowchart For Verifying if 2 numbers are Amicable number

    Algorithm for Amicable numbers

    What is Amicable Number