AMICABLE NUMBER (FRIENDLY NUMBER) OR NOT

    

 

Consider the following I/O samples.


SAMPLE INPUT: 220 284

SAMPLE OUTPUT: AMICABLE PAIR


Amicable numbers are two different numbers related in such a way that the sum of the proper divisors of each is equal to the other number.


Sum of divisors of 220 = 284   

Sum of divisors of 284 = 220

sum of 220==284 && sum of 284==220


C PROGRAM:

#include<stdio.h>

int main()

{

   int n1,n2,i,sum1=0,sum2=0;

    scanf("%d %d",&n1,&n2);

    for(i=1;i<n1;i++)

    {

        if(n1%i==0)

            sum1+=i;

    }

    for(i=1;i<n2;i++)

    {

        if(n2%i==0)

            sum2+=i;

    }

    

    if(sum1==n2 && sum2==n1)

        printf("Amicable Pairs");

    else

        printf("Not a Amicable Pairs");

    return 0;

}


OUTPUT:




The given source code in C program "FOR AMICABLE PAIRS OR NOT" is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 

If you have any feedback about this article and want to improve this, please comment in the comment section.


Comments

Popular posts from this blog

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

INVERTED PYRAMID STAR PATTERN

Design a way to sort the list of positive integers in the descending order according to frequency of elements. The elements with integers with higher frequency come before with lower frequency elements with same frequency come in the same order as they appear the values.