- 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

# Squared sum of n odd numbers - JavaScript

We are required to write a JavaScript function that takes in a Number, say n, and finds the sum of the square of first n odd natural Numbers.

For example −

If the input number is 3. Then the output will be −

1^2 + 3^2 + 5^2 = 35

Therefore, the output is −

35

## Example

Following is the code −

const num = 3; const squaredSum = num => { let sum = 0; for(let i = 1; i <= num; i++){ sum += Math.pow((2 * i) - 1, 2); }; return sum; }; console.log(squaredSum(num));

## Output

Following is the output in the console −

35

- Related Questions & Answers
- Sum of square of first n odd numbers
- N consecutive odd numbers JavaScript
- Squared and square rooted sum of numbers of an array in JavaScript
- Program to find sum of first N odd numbers in Python
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers - JavaScript
- Program to find the sum of first n odd numbers in Python
- Average of first n odd naturals numbers?
- Finding all the n digit numbers that have sum of even and odd positioned digits divisible by given numbers - JavaScript
- Integers have sum of squared divisors as perfect square in JavaScript
- Sum of sum of first n natural numbers in C++
- Sum of the first N Prime numbers
- Print all odd numbers and their sum from 1 to n in PL/SQL
- Sum of square-sums of first n natural numbers
- Sum of even numbers from n to m regardless if n<m or n>m JavaScript
- Minimize the sum of squares of sum of N/2 paired formed by N numbers in C++

Advertisements