about | help | code help+videos | done | prefs |
apcsaLoopsAddMultiplyInclusive
Given two ints a and b, add every ODD number between a and b and MULTIPLY by every even number between a and b. So if a is 4 and b is 9, the result should be 305, the result of (5*6+7)*8+9. Notice that the multiplication operation relies on the running total thus far. Notice also that if a is even, it will not be part of the output. For all inputs, a < b is a precondition (a is guaranteed to be less than b for all inputs). Remember that the remainder operator % can be used to find the remainder during division. When you divide an odd number by 2, the remainder is 1. HINTYou need a loop to do this. apcsaLoopsAddMultiplyInclusive(4, 9) → 305 apcsaLoopsAddMultiplyInclusive(5, 8) → 296 apcsaLoopsAddMultiplyInclusive(-10, -4) → 1580 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 150
Copyright Nick Parlante 2017 - privacy