//A pair of amicable numbers is a pair such that the properdivisors of one numbe
ID: 3609119 • Letter: #
Question
//A pair of amicable numbers is a pair such that the properdivisors of one number sum to the other and vice versa. Write a Cprogram to output pairs of amicable numbers less than a numberspecified by the user...Define a function int sum_of_dividers(int)for computing the sum of the divisors...here's what the output should be (sample):
Input an Integer: 3000
220 and 284
1184 and 1210
2620 and 2924
//here's what ive done so far...but no outputs whatsoever...
#include <stdio.h>
int sum_of_dividers (int n);
int haverim (int a, int b);
int main ()
{
int k,n,v;
printf("Input an Integer: ");
scanf ("%d",&v);
for (k=1;k<v;k++)
if (haverim (k,v))
printf ("%d,%d ",k,v);
return 0;
}
int haverim (int a, int b)
{
return (sum_of_dividers(a)==b &&sum_of_dividers(b)==a);
}
int sum_of_dividers (int n)
{
int k,sum=1;
for (k=2;k*k<n;k++)
if (n%k==0)
sum+=k+n/k;
if (k*k==n)
sum+=k;
return sum;
}
Explanation / Answer
please rate - thanks you weren't checking every combination of numbers, only everynumber and v corrections in red //here's what ive done so far...but no outputs whatsoever... #include #include //needed for getch int sum_of_dividers (int n); int haverim (int a, int b); int main () { int k,n,v,j; printf("Input an Integer: "); scanf ("%d",&v); for (k=1;kRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.