Q. writes a C program to check whether given two numbers are amicable numbers or not.
Ans.
Definition of Amicable numbers: 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.
For example, lets a pair or two number pair is (220,284),
For the proper divisor of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110, of which the sum is 284.
And the proper divisor of 284 are 1, 2, 4, 71, 142 of which the sum is 220.
/*program to check whether given numbers are amicable or not*/
#include<stdio.h>
#include<conio.h>
int main()
{
int n1,n2,s1=0,s2=0,i;
printf("Enter first number : ");
scanf("%d",&n1);
printf("Enter second number : ");
scanf("%d",&n2);
for(i=1; i<n1 ; i++)
{
if(n1%i==0)
s1=s1+i;
}
for(i=1; i<n2 ; i++)
{
if(n2%i==0)
s2=s2+i;
}
if(n1==s2 && n2==s1)
printf("Given numbers are Amicable Numbers");
else
printf("Given numbers are Not Amicable Numbers");
getch();
getch();
return 0;
}
Output:-
Enter first number : 452
Enter second number : 264
Given numbers are Not Amicable Numbers
Enter first number : 220
Enter second number : 284
Given numbers are Amicable Numbers
- Search Perfect number C program
- Search Armstrong number C program
- Print Armstrong number range C program
- Flowchart for check a number is Armstrong or not
No comments:
Post a Comment