

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sum all perfect cube values upto n using JavaScript
Problem
We are required to write a JavaScript function that takes in a number n and returns the sum of all perfect cube numbers smaller than or equal to n.
Example
Following is the code −
const num = 23546; const sumPerfectCubes = (num = 1) => { let i = 1; let sum = 0; while(i * i * i <= num){ sum += (i * i * i); i++; }; return sum; }; console.log(sumPerfectCubes(num));
Output
164836
- Related Questions & Answers
- Count numbers upto N which are both perfect square and perfect cube in C++
- Count all triplets whose sum is equal to a perfect cube in C++
- Finding all possible prime pairs that sum upto input number using JavaScript
- Prime numbers upto n - JavaScript
- Finding sum of sequence upto a specified accuracy using JavaScript
- C Program for cube sum of first n natural numbers?
- C++ Program for cube sum of first n natural numbers?
- Python Program for cube sum of first n natural numbers
- Java Program to cube sum of first n natural numbers
- Counting the number of 1s upto n in JavaScript
- Sum all duplicate values in array in JavaScript
- C Program for the cube sum of first n natural numbers?
- Program for cube sum of first n natural numbers in C++
- Find fibonacci series upto n using lambda in Python
- Print n numbers such that their sum is a perfect square
Advertisements