Thread Subject: differnt methods to sum positive numbers to achieve a number

Subject: differnt methods to sum positive numbers to achieve a number

From: Amir Hossein

Date: 12 Dec, 2008 14:56:03

Message: 1 of 3

consider that we have a number. for example 5. i want to know how i can writhe a code to mention all the different ways that positive numbers can be summed up to give 5.
1+1+1+1+1
2+3
2+2+1

Subject: differnt methods to sum positive numbers to achieve a number

From: Jos

Date: 12 Dec, 2008 15:45:05

Message: 2 of 3

"Amir Hossein " <a.gharehgozli@gmail.com> wrote in message <ghtu23$ikh$1@fred.mathworks.com>...
> consider that we have a number. for example 5. i want to know how i can writhe a code to mention all the different ways that positive numbers can be summed up to give 5.
> 1+1+1+1+1
> 2+3
> 2+2+1

What about 0.1, 0.001, pi, 4.99999999999 etc. These are also positive numbers! Or do you mean integers only?

I suggest you get some inspiration for writing your own code by looking at some of the excellent submissions by JohnD'Errico on the File Exchange.

hth
Jos

Subject: differnt methods to sum positive numbers to achieve a number

From: Walter Roberson

Date: 12 Dec, 2008 15:50:48

Message: 3 of 3

Amir Hossein wrote:
> consider that we have a number. for example 5. i want to know how i can writhe
> a code to mention all the different ways that positive numbers can be summed up to give 5.
> 1+1+1+1+1
> 2+3
> 2+2+1

Consider using recursion.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com