You will be given two numbers, N and K. Write a MATLAB function that will determine how many different unique ways you can have K numbers add up to N. The numbers you use can be anything from 0-N, but no negatives and no fractions. For example, five can be the sum of three numbers in five different ways:
- 5+0+0
- 4+1+0
- 3+2+0
- 3+1+1
- 2+2+1
Order does not matter, so (5,0,0) is the same as (0,0,5) and (0,5,0). Therefore, the output of your function num_sum(5,3) should be 5. I don't need the different permutations, only how many there are. Good luck!
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers29
Suggested Problems
-
Given an unsigned integer x, find the largest y by rearranging the bits in x
2049 Solvers
-
Project Euler: Problem 7, Nth prime
1771 Solvers
-
Project Euler: Problem 16, Sums of Digits of Powers of Two
181 Solvers
-
178 Solvers
-
Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.
959 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!