You are here:

# C++/c++ (program)

Advertisement

Question
In the first century A.D. numbers were separated into "abundant" (such as 12, whose divisors have a sum greater than 12)"deficient"(such as 9, whose divisors have a sum less than 9), and "perfect"(such as 6, whose divisors add up to 6), In all cases, the number itself is not included. For example, the only numbers that divide evenly into 6 are 1,2,3, and 6; and 6=1+2+3.
Can you write a program that list all numbers between 2 and 30 and classify each as abundant, deficient, or perfect

Answer
int inum = 2,irem,iquo;
while(inum <= 30)
{
int i =1;
irem = 1;
while(irem > 0)
{
i++;
irem = inum%i;

}

iquo = inum /i;
int itemp = 0;
if( inum == i)
itemp = iquo+i;
if(inum != i)
itemp = 1+iquo+i;

if(itemp > inum)
cout<<"the number is abundant"<<inum<<"\n";
if(itemp < inum)
cout<<"the number is deficent"<<inum<<"\n";
if(itemp == inum)
cout<<"the number is perfect"<<inum<<"\n";

inum++;
}
Here is the code. Let me know if there is any problem

C++

All Answers

Answers by Expert:

Ask Experts

Volunteer

#### rakshitha

##### Expertise

Difficult questions related to C .

##### Experience

C ,vc ,opc ,windows CE, ActiveX

Education/Credentials
Masters in electrical engineering

©2017 About.com. All rights reserved.

Browse Answers: