943,866 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1133
  • C++ RSS
Apr 4th, 2009
0

c++ I did not understand

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MoOou is offline Offline
5 posts
since Apr 2009
Apr 4th, 2009
0

Re: c++ I did not understand

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.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Apr 4th, 2009
0

Re: c++ I did not understand

Click to Expand / Collapse  Quote originally posted by MoOou ...
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 .
Reputation Points: 92
Solved Threads: 20
Posting Whiz
rahul8590 is offline Offline
351 posts
since Mar 2009
Apr 5th, 2009
0

Re: c++ I did not understand

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??
Last edited by MoOou; Apr 5th, 2009 at 1:55 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MoOou is offline Offline
5 posts
since Apr 2009
Apr 5th, 2009
0

Re: c++ I did not understand

n=mt is the other way of writing that
\frac{n}{m}=t where t 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
Reputation Points: 1486
Solved Threads: 140
Practically a Posting Shark
siddhant3s is offline Offline
816 posts
since Oct 2007
Apr 5th, 2009
0

Re: c++ I did not understand

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
Reputation Points: 92
Solved Threads: 20
Posting Whiz
rahul8590 is offline Offline
351 posts
since Mar 2009
Apr 5th, 2009
0

Re: c++ I did not understand

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"





Click to Expand / Collapse  Quote originally posted by rahul8590 ...
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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
fefe is offline Offline
2 posts
since Apr 2009
Apr 5th, 2009
0

Re: c++ I did not understand

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"
Reputation Points: 10
Solved Threads: 1
Newbie Poster
fefe is offline Offline
2 posts
since Apr 2009
Apr 5th, 2009
0

Re: c++ I did not understand

C++ Syntax (Toggle Plain Text)
  1. input n
  2. vector<int> factors
  3. for(int i = 2; i <= n/2; ++n)
  4. //check if i is factor of n
  5. //if it is add it to the vector
  6.  
  7. //declare variable to act as running total and initalize to zero
  8.  
  9. //loop through vector adding elements together
  10. for(int i = 0; i < size of vector; ++i)
  11. //add each element to previous total
  12.  
  13. //if n equals total from above loop, then n is a perfect number.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: STL beginner needs helps
Next Thread in C++ Forum Timeline: Make base pyramid





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC