c++ I did not understand

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2009
Posts: 5
Reputation: MoOou is an unknown quantity at this point 
Solved Threads: 0
MoOou MoOou is offline Offline
Newbie Poster

c++ I did not understand

 
0
  #1
Apr 4th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,688
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 265
Lerner Lerner is offline Offline
Posting Virtuoso

Re: c++ I did not understand

 
0
  #2
Apr 4th, 2009
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.
Klatu Barada Nikto
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 211
Reputation: rahul8590 is on a distinguished road 
Solved Threads: 11
rahul8590's Avatar
rahul8590 rahul8590 is offline Offline
Posting Whiz in Training

Re: c++ I did not understand

 
0
  #3
Apr 4th, 2009
Originally Posted by MoOou View 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

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 .
<?php
$data = $_POST['data'];
if(empty($data)) {
echo "byte me" ; }
?>
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 5
Reputation: MoOou is an unknown quantity at this point 
Solved Threads: 0
MoOou MoOou is offline Offline
Newbie Poster

Re: c++ I did not understand

 
0
  #4
Apr 5th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 793
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: c++ I did not understand

 
0
  #5
Apr 5th, 2009
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
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 211
Reputation: rahul8590 is on a distinguished road 
Solved Threads: 11
rahul8590's Avatar
rahul8590 rahul8590 is offline Offline
Posting Whiz in Training

Re: c++ I did not understand

 
0
  #6
Apr 5th, 2009
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
<?php
$data = $_POST['data'];
if(empty($data)) {
echo "byte me" ; }
?>
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 2
Reputation: fefe is an unknown quantity at this point 
Solved Threads: 1
fefe fefe is offline Offline
Newbie Poster

Re: c++ I did not understand

 
0
  #7
Apr 5th, 2009
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"





Originally Posted by rahul8590 View Post
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 2
Reputation: fefe is an unknown quantity at this point 
Solved Threads: 1
fefe fefe is offline Offline
Newbie Poster

Re: c++ I did not understand

 
0
  #8
Apr 5th, 2009
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"
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,688
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 265
Lerner Lerner is offline Offline
Posting Virtuoso

Re: c++ I did not understand

 
0
  #9
Apr 5th, 2009
  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.
Klatu Barada Nikto
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC