Input two numbers and print whether they are amicable pairs or not.
N.B. [ Example of amicable pairs: - 220, 284, 1184, 1210, 2620, 2924, 5620, 5564, 6232, 6368 ]
#include <stdio.h>
#include <conio.h>
int s_o_f ( int );
int amicable( int, int );
void main ( )
{
int n1, n2 , f;
clrscr ( );
printf("\n\n\n\t\t Enter 1st number..:"); scanf("%d",&n1);
printf("\n\n\t\t Enter 2nd number..:"); scanf("%d",&n2);
f = amicable ( n1, n2 );
if ( f == 1 )
{
printf("\n\n\n\t\t Numbers are amicable pair.");
}
else
{
printf("\n\n\n\t\t Numbers are not amicable pairs.");
}
getch ( );
}
int amicable ( int n1, int n2 )
{
int s1, s2;
s1 = s_o_f ( n1 );
s2 = s_o_f ( n2 );
if ( s1 == n2 && s2 == n1 )
{
return 1;
}
else
{
return 0;
}
}
int s_o_f ( int n )
{
int s = 0, i;
for ( i = 1; i < n; i++ )
{
if ( n % i == 0 )
{
s = s + i;
}
}
return s;
}
Click here to contact us
N.B. [ Example of amicable pairs: - 220, 284, 1184, 1210, 2620, 2924, 5620, 5564, 6232, 6368 ]
#include <stdio.h>
#include <conio.h>
int s_o_f ( int );
int amicable( int, int );
void main ( )
{
int n1, n2 , f;
clrscr ( );
printf("\n\n\n\t\t Enter 1st number..:"); scanf("%d",&n1);
printf("\n\n\t\t Enter 2nd number..:"); scanf("%d",&n2);
f = amicable ( n1, n2 );
if ( f == 1 )
{
printf("\n\n\n\t\t Numbers are amicable pair.");
}
else
{
printf("\n\n\n\t\t Numbers are not amicable pairs.");
}
getch ( );
}
int amicable ( int n1, int n2 )
{
int s1, s2;
s1 = s_o_f ( n1 );
s2 = s_o_f ( n2 );
if ( s1 == n2 && s2 == n1 )
{
return 1;
}
else
{
return 0;
}
}
int s_o_f ( int n )
{
int s = 0, i;
for ( i = 1; i < n; i++ )
{
if ( n % i == 0 )
{
s = s + i;
}
}
return s;
}
Click here to contact us