BETROTHED NUMBERS OR NOT

Consider the following I/O samples.



SAMPLE INPUT: 153

SAMPLE OUTPUT:  BETROTHED NUMBER


Betrothed numbers are two positive integers such that the sum of the proper divisors of either number is one more than the value of the other number.


Divisors of 48 : 1, 2, 3, 4, 6, 8, 12, 16, 24. Their sum is 76. (75+1)

Divisors of 75 : 1, 3, 5, 15, 25. Their sum is 49. (48+1)





C PROGRAM:

#include <stdio.h>

int main()

{

    int num1,num2,sum1=0,sum2=0,i;

    scanf("%d %d",&num1,&num2);

    for(i=1;i<=num1/2;i++)

    {

        if(num1%i==0)

            sum1+=i;

    }

    for(i=1;i<=num2/2;i++)

    {

        if(num2%i==0)

            sum2+=i;

    }

    if(sum1-1 == num2 && sum2-1 == num1)

        printf("BETROTHED NUMBER");

    else

        printf("NOT A BETROTHED NUMBER");

    return 0;

 }





OUTPUT:





The given source code in C program "FOR BETROTHED NUMBER 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

INVERTED PYRAMID STAR PATTERN

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

C PROGRAM TO PRINT THE REMAINING DAYS AND COMPLETED DAYS FROM A GIVEN DATE