Question: C++ ONLY. Write a function sumOfMultiples , that inputs two integers - seed and cap. The function should return the sum of all the multiples

C++ ONLY.

Write a function sumOfMultiples, that inputs two integers - seed and cap. The function should return the sum of all the multiples of seed present between 1 and cap (both inclusive).

  • Your function should be named sumOfMultiples.

  • Your function has two input arguments in the order:

  1. seed: integer argument whose multiples need to be summed.
  2. cap: integer argument indicating the upper limit of the multiples to be added.
  • Your function should return the sum of the multiples: an integer value.

  • Your function should not print/output anything

Examples:

  • For the input arguments sumOfMultiples(6, 20), the function should return 36. (Explanation: the multiples of 6 between 1 and 20 are 6, 12 and 18. The sum of which being 36).
  • For the input arguments sumOfMultiples(1, 3), the function should return 6. (Explanation: the multiples of 1 between 1 and 3 are 1, 2 and 3. The sum of which being 6).

Note: You do not need to write the main(), the include, or namespace commands, you only need to write the function definition.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!