I have a question I did not understand if anyone of you understood it please explain to me

suppose that m and n are integers and m is nonzero. Recall that m is called a divisor of n if n=mt for some integer t; that is, when m divides n, the remainder is 0. moreover .m is called a proper divisor of n if m<n and m divides n. a positive integer is called perfect if it is the sum of its positive proper divisors. for example, the positive proper divisors of 28 are 1,2,4,7 and 14 and 1+2+4+7=28. therefore 28 is perfect. write a program that does the following;
a.output the first four perfect integers.
b.takes as input a positive integer and then outputs whether the integer is perfect.

and thank you a lot

Recommended Answers

All 8 Replies

Do you have a problem with the math involved or the C++ involved? The easiest way to do the math you need using C++ is to use the modulo operator. Assuming m and n are both postive integers, if the result of m % n is zero then, n is a positive proper divisor of m according to the description you provided.

I have a question I did not understand if anyone of you understood it please explain to me

suppose that m and n are integers and m is nonzero. Recall that m is called a divisor of n if n=mt for some integer t; that is, when m divides n, the remainder is 0. moreover .m is called a proper divisor of n if m<n and m divides n. a positive integer is called perfect if it is the sum of its positive proper divisors. for example, the positive proper divisors of 28 are 1,2,4,7 and 14 and 1+2+4+7=28. therefore 28 is perfect. write a program that does the following;
a.output the first four perfect integers.
b.takes as input a positive integer and then outputs whether the integer is perfect.

and thank you a lot

well ur inputted with a number for ex lets take the no 28 ( which is in ur ex)
1. (this one is for proper divisor )
u will have to find such nos that divide 28 completely i.e
28 % number = = 0
the remainder must be zero
thus you will land up in 1 , 2, 4, 7 , 14

2. then when u find these numbers , u will have to find the summation of these in such a manner that
their sum is equal to 28
i.e in this case 1+2+4+7+14 = 28

thus the number 28 becomes perfect positive number .

there is something I did not understand we prompt the user to put the numbers or one number only??
what's n=mt ??
we have to use if in these statement (m!=0)(m%n==0)(m<n) right??
and we don't need to use loop, right??

[TEX]n=mt[/TEX] is the other way of writing that
[TEX]\frac{n}{m}=t [/TEX] where [TEX]t[/TEX] is a integer

it means that if you divide n by m, the division should leave no remainder.

>>we have to use if in these statement (m!=0)(m%n==0)(m<n) right??
yes


>>and we don't need to use loop, right??
No

You will have to use the loops for the first part of the question

well let me simply for you ..

1. accept number(`s in form of for loop or so ) and perfrom step 1 of my previous post .
you will land up with alll the divisors of that particular number (which will be the current number of for loop ) .
store it in some kinda array .

2. now check the summation of these numbers (which are divisors of the number inputted). if the add up to the number which is inputted , then the number which is inputted is perfect .

now re run the for loop and find such first 4 perfect numbers

can u please give us the full program for this question

"suppose that m and n are integers and m is nonzero. Recall that m is called a divisor of n=mt for some integers t; that is when m divides n, the remainders is 0,moreover,m is called a proper divisor of n if m<n and m divides n .a positive integers is called perfect if it is the sum of its positive proper divisors .for example the positive divisor of 28 are 1,2,4,7 and 14 and 1+2+4+7+14=28,thrfore 28 is perfect write a program that does the following :a)output the first four perfect integers b)takes as input a positive integers and then outputs whether the integers is perfect"


well let me simply for you ..

1. accept number(`s in form of for loop or so ) and perfrom step 1 of my previous post .
you will land up with alll the divisors of that particular number (which will be the current number of for loop ) .
store it in some kinda array .

2. now check the summation of these numbers (which are divisors of the number inputted). if the add up to the number which is inputted , then the number which is inputted is perfect .

now re run the for loop and find such first 4 perfect numbers

please help me to get the full program for writing this question
"suppose that m and n are integers and m is nonzero. Recall that m is called a divisor of n=mt for some integers t; that is when m divides n, the remainders is 0,moreover,m is called a proper divisor of n if m<n and m divides n .a positive integers is called perfect if it is the sum of its positive proper divisors .for example the positive divisor of 28 are 1,2,4,7 and 14 and 1+2+4+7+14=28,thrfore 28 is perfect write a program that does the following :a)output the first four perfect integers b)takes as input a positive integers and then outputs whether the integers is perfect"

input n
vector<int> factors
for(int i = 2; i <= n/2; ++n)
   //check if i is factor of n
   //if it is add it to the vector

//declare variable to act as running total and initalize to zero

//loop through vector adding elements together
for(int i = 0; i < size of vector; ++i)
    //add each element to previous total

//if n equals total from above loop, then n is a perfect number.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.