# Answer to Question #17809 in C++ for Asma

Question #17809

A positive number N is called as perfect if the sum of its divisors is equal to N. For example, 28 is called as perfect since the sum of its divisors 1, 2, 4, 7, and 14 is equal to 28.

1- Write a C++ program that reads any positive integer and checks whether the number is perfect or not.

2- Display all the numbers between 2 and 10000 that are called perfect.

1- Write a C++ program that reads any positive integer and checks whether the number is perfect or not.

2- Display all the numbers between 2 and 10000 that are called perfect.

Expert's answer

1)

#include <iostream>

using namespace std;

main()

{int n,s=1,i=2,k=-1;

cout<<"Enter N: ";

cin>>n;

while(i<n){

if(n%i==0)

s+=i;

i++;

}

if(s==n)

cout<<" Perfect\n";

else cout<<" not perfect\n";

system("pause");

& }

2)

#include <iostream>

using namespace std;

main()

{int n,s=1,i=2,k=-1;

cout<<" Perfect:\n";

for (n=1;n<10000;n++){

while(i<n){

if(n%i==0)

s+=i;

i++;

}

if(s==n)

cout<<n<<" ";

& i=2;

& s=1;&

}

cout<<"\n";

system("pause");

& }

#include <iostream>

using namespace std;

main()

{int n,s=1,i=2,k=-1;

cout<<"Enter N: ";

cin>>n;

while(i<n){

if(n%i==0)

s+=i;

i++;

}

if(s==n)

cout<<" Perfect\n";

else cout<<" not perfect\n";

system("pause");

& }

2)

#include <iostream>

using namespace std;

main()

{int n,s=1,i=2,k=-1;

cout<<" Perfect:\n";

for (n=1;n<10000;n++){

while(i<n){

if(n%i==0)

s+=i;

i++;

}

if(s==n)

cout<<n<<" ";

& i=2;

& s=1;&

}

cout<<"\n";

system("pause");

& }

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment