Answer to Question #162366 in C++ for Aarati

Question #162366

int x, i;

x = 28;

int fsum = 0;

for(int i=1; i<=x; i++){

if( x%i == 0 )

fsum += i ;

}

cout<<fsum<<endl;

if ( fsum == 2*x )

cout<<1<<endl;

else

cout<<0<<endl;

1.If the program in the previous question is modified to read 'n' from keyboard (instead of assigning a constant inside the program). In general, what does such a modified program print?


NOTE - Perfect number is a positive integer that is equal to the sum of its proper divisors.


(a) The program prints the sum of proper divisors of n, followed by 1 if it is a perfect number and 0 if it is not.

(b)The program prints the sum of all divisors of n, followed by 0 if it is a perfect number and 1 if it is not.

(c) The program prints the sum of proper divisors of n, followed by 0 if it is a perfect number and 1 if it is not.

(d) The program prints the sum of all divisors of n, followed by 1 if it is a perfect number and 0 if it is not.


1
Expert's answer
2021-02-09T15:27:03-0500


The answer is d)

that is to say:

The program prints the sum of all divisors of n, followed by 1 if it is a perfect number and 0 if it is not.

sum of all divisors of 28 is 56 and it is a perfect number


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment