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

[885 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

                 



Having Difficulty understanding above Algorithm and Flowchart? Buy my Personal Notes



Are You Good enough in Algorithms? Prove it!



Comments

49 comment
  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    -1 OR 2+780-780-1=0+0+0+1 --

  • zbdrariI

    -1 OR 3+780-780-1=0+0+0+1 --

  • zbdrariI

    -1 OR 2+357-357-1=0+0+0+1

  • zbdrariI

    -1 OR 3+357-357-1=0+0+0+1

  • zbdrariI

    -1' OR 2+98-98-1=0+0+0+1 --

  • zbdrariI

    -1' OR 3+98-98-1=0+0+0+1 --

  • zbdrariI

    -1' OR 2+352-352-1=0+0+0+1 or 'Yv6RQIFL'='

  • zbdrariI

    -1' OR 3+352-352-1=0+0+0+1 or 'Yv6RQIFL'='

  • zbdrariI

    -1" OR 2+965-965-1=0+0+0+1 --

  • zbdrariI

    -1" OR 3+965-965-1=0+0+0+1 --

  • zbdrariI

    if(now()=sysdate(),sleep(15),0)

  • zbdrariI

    0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z

  • zbdrariI

    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z

  • zbdrariI

    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

  • zbdrariI

    1 waitfor delay '0:0:15' --

  • zbdrariI

    KJYwROpM'; waitfor delay '0:0:15' --

  • zbdrariI

    pF9ODz8y' OR 209=(SELECT 209 FROM PG_SLEEP(15))--

  • zbdrariI

    5kCUOqW5') OR 798=(SELECT 798 FROM PG_SLEEP(15))--

  • zbdrariI

    ZAWCMfzf')) OR 177=(SELECT 177 FROM PG_SLEEP(15))--

  • zbdrariI

    e'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

  • zbdrariI

    1'"

  • zbdrariI

    @@w9puO

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e

  • zbdrariI

    e





Search
Get Answers to your Programming Questions


Recommended Deals ends in








Test Your Skills:

Search Tags

    Amicable Number checker Algorithm

    Amicable Number Verifier Pseudocode

    Flowchart For Verifying if 2 numbers are Amicable number

    Algorithm for Amicable numbers