Question: To solve this problem, write a VBA function called Packing that allows the user to specify a container size (a positive number). For this size,
To solve this problem, write a VBA function called Packing that allows the user to specify a container size (a positive number). For this size, your function should return the largest number n where the sum 1 + 2 + + n is no larger than the specified container size. Your function should have the following general form:
1. Begin by assuming that n is 0 2. Also, assume that the sum is initially 0 3. Set up a Do/While loop that iterates while the sum does not exceed the specified size 4. Inside the loop, increase n by 1 (e.g., n = n + 1) 5. Also inside the loop, update the sum to include the new n value 6. Your loop will stop only when n is too large, so after the loop, subtract one from n
Include comments in your function that explain how it works.
You can verify that your function is working by trying these cases. If the size is 6, then n = 3. If the size is 40, then n = 8.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
