I have a method named henry
that takes two integer arguments, i
and j
, and returns the sum of the ith
and jth
perfect numbers. For example, henry(1, 3)
should return 502
because 6
is the 1st perfect number
and 496
is the 3rd perfect number
and 6 + 496 = 502.
int henry (int i, int j)
{
//how do i start
}
I know how to print perfect number like this:
int main()
{
int i, j, n, sum = 0;
/* Reads upper limit to print perfect numbers upto */
printf("Enter any number to print perfect number up to: ");
scanf("%d", &n);
printf("\nAll Perfect numbers between 1 to %d:\n", n);
/*
* Iterates from 1 to n and print if it is perfect number
*/
for(i=1; i<=n; i++)
{
sum = 0;
/*
* Checks whether the current number i is Perfect number or not
*/
for(j=1; j<i; j++)
{
if(i%j==0)
{
sum += j;
}
}
/* If the current number i is Perfect number */
if(sum == i)
{
printf("%d is Perfect Number\n", i);
}
}
return 0;
}
Please give me hint to solve this problem, thank you.