/*Program to check two numbers are amicable given or not*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sum=0,i,j,add=0;
clrscr();
printf("Enter A: ");
scanf("%d",&a);
printf("Enter B: ");
scanf("%d",&b);
for(i=1;i<a;i++)
{
if(a%i==0)
{
sum=sum+i;
}
}
for(j=1;j<b;j++)
{
if(b%j==0)
{
add=add+j;
}
}
if(sum==b && add==a)
{
printf("%d and %d are amicable numbers",a,b);
}
else
{
printf("%d and %d are not amicable numbers",a,b);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sum=0,i,j,add=0;
clrscr();
printf("Enter A: ");
scanf("%d",&a);
printf("Enter B: ");
scanf("%d",&b);
for(i=1;i<a;i++)
{
if(a%i==0)
{
sum=sum+i;
}
}
for(j=1;j<b;j++)
{
if(b%j==0)
{
add=add+j;
}
}
if(sum==b && add==a)
{
printf("%d and %d are amicable numbers",a,b);
}
else
{
printf("%d and %d are not amicable numbers",a,b);
}
getch();
}
No comments:
Post a Comment