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.
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
Comments
Leave a comment