Skip to content

Latest commit

 

History

History
18 lines (11 loc) · 551 Bytes

SumOfCubes.md

File metadata and controls

18 lines (11 loc) · 551 Bytes

Problem 9: Sum of Cubes

Write a method to compute the sum of the cubes of the first n natural numbers using loops and conditionals.

Explanation

The sum of the cubes of the first n natural numbers is the result of adding the cubes of all numbers from 1 to n. For example, the sum of the cubes of the first 3 natural numbers (1^3 + 2^3 + 3^3) is 36.

Constraints

  • The method should not use any formula for the sum of cubes.
  • The method should handle large values of n efficiently.

Example

sumOfCubes(3); // returns 36