/*Amicable Numbers are two numbers so related that the sum of the proper divisors of the one is equal to the other, unity being considered as a proper divisor but not the number itself. Such a pair is (220, 284).*/
main()
{
int num1, num2, i, t1=0,t2=0;
clrscr();
printf("Enter two numbers to check whether they are amicable numbers or not. --> ");
scanf("%d%d",&num1,&num2);
for(i=1;i<num1;i++)
{
if(num1%i==0)
t1=t1+i;
}
for(i=1;i<num2;i++)
{
if(num2%i==0)
t2=t2+i;
}
if(t1==num2 && t2==num1)
printf("\(%d,%d\) are amicable numbers.",num1,num2);
else
printf("\(%d,%d\) are not amicable numbers.",num1,num2);
getch();
}
Output:
main()
{
int num1, num2, i, t1=0,t2=0;
clrscr();
printf("Enter two numbers to check whether they are amicable numbers or not. --> ");
scanf("%d%d",&num1,&num2);
for(i=1;i<num1;i++)
{
if(num1%i==0)
t1=t1+i;
}
for(i=1;i<num2;i++)
{
if(num2%i==0)
t2=t2+i;
}
if(t1==num2 && t2==num1)
printf("\(%d,%d\) are amicable numbers.",num1,num2);
else
printf("\(%d,%d\) are not amicable numbers.",num1,num2);
getch();
}
Output:
No comments:
Post a Comment