Write a function perfect that determines whether anumber is a perfect number or
ID: 3616000 • Letter: W
Question
Write a function perfect that determines whether anumber is a perfect number or not. This function should receive anumber and return true if the number is perfectand false otherwise. Use this function in aprogram that determines and prints all the perfect numbers between1 and 1000. Print the divisors of each perfect number to confirmthat the number is indeed perfect as shown in the sample outputbelow.
An integer is said to be a perfect number if the sum ofits divisors, including 1 (but not the number itself), is equal tothe number. For example, 6 is a perfect number, because 6 = 1 + 2 +3.
Sample output
Perfect integers between 1 and 1000:
6 = 1 + 2 + 3
28 = 1 + 2 + 4 + 7 + 14
496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248
Explanation / Answer
Already solved by me on the link
intperfectNumber(int);
int main()
{
clrscr();
cout<<"this progame will print all the perfectnumbers ";
for(short v=2;v<=1000;v++)
if(perfectNumber(v))
{
cout<<v<<" factors are:";
for(short c=1;c<v;c++)
if(v%c==0)
cout<<c<<" ";
cout<<endl;
}
getch();
return 0;
}
int perfectNumber(intnum)
{
int sum=0, r;
for(short v=1;v<num;v++)
{
r=num%v;
if(r==0)
sum=sum+v;
}
if(sum==num)
return 1;
return 0;
}
hope you will rate higher
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.