C program to find amicable numbers
Output:
Enter two numbers to check they are amicable or not:
220
284
220 and 284 are amicable numbers
Implementation:
Output:
Enter two numbers to check they are amicable or not:
220
284
220 and 284 are amicable numbers
Implementation:
/* Amicable numbers are the numbers which has their sum of divisors equal to one another For example: consider the numbers a=220 and b=284 the divisors of 220 are: 1 2 4 5 10 11 20 22 44 55 110 the divisors of 284 are: 1 2 4 71 142 Now, adding the divisors of 220 1+2+4+5+10+11+20+22+44+55+110 = 284 , which is equal to number b=284 Now, adding the divisors of 284 1+2+4+71+142 = 220, which is equal to number a=220 Hence, the numbers 220 and 284 are amicable numbers */ #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { int number1,number2,suma=0,sumb=0; int i; printf("Enter two numbers to check they are amicable or not:\n"); scanf("%d %d",&number1,&number2); for(i=1;i<=(number1/2);i++) { if(number1%i==0) { suma += i; } } for(i=1;i<=(number2/2);i++) { if(number2%i==0) { sumb += i; } } if(suma == number2 && sumb == number1) { printf("%d and %d are amicable numbers",number1,number2); } else { printf("%d and %d are not amicable numbers",number1,number2); } }