- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 of square of first n odd numbers
The series of squares of first n odd numbers takes squares of of first n odd numbers in series.
The series is: 1,9,25,49,81,121…
The series can also be written as − 12, 32, 52, 72, 92, 112….
The sum of this series has a mathematical formula −
n(2n+1)(2n-1)/ 3= n(4n2 - 1)/3
Lets take an example,
Input: N = 4 Output: sum =
Explanation
12 + 32 + 52 + 72 = 1 +9+ 25 + 49 = 84
Using formula, sum = 4(4(4)2- 1)/3 = 4(64-1)/3 = 4(63)/3 = 4*21 = 84 both these methods are good but the one using mathematical formula is better because it does not use looks which reduces its time complexity.
Example
#include <stdio.h> int main() { int n = 8; int sum = 0; for (int i = 1; i <= n; i++) sum += (2*i - 1) * (2*i - 1); printf("The sum of square of first %d odd numbers is %d",n, sum); return 0; }
Output
The sum of square of first 8 odd numbers is 680
Example
#include <stdio.h> int main() { int n = 18; int sum = ((n*((4*n*n)-1))/3); printf("The sum of square of first %d odd numbers is %d",n, sum); return 0; }
Output
The sum of square of first 18 odd numbers is 7770
- Related Articles
- Find the sum of first $n$ odd natural numbers.
- Sum of square-sums of first n natural numbers
- Program to find sum of first N odd numbers in Python
- Swift Program to calculate the sum of first N odd numbers
- Program to find the sum of first n odd numbers in Python
- Average of first n odd naturals numbers?
- Difference between sum of the squares of and square of sum first n natural numbers.
- Squared sum of n odd numbers - JavaScript
- PHP program to calculate the sum of square of first n natural numbers
- Sum of the first N Prime numbers
- Sum of sum of first n natural numbers in C++
- Sum of first n natural numbers in C Program
- Find maximum N such that the sum of square of first N natural numbers is not more than X in Python
- Find maximum N such that the sum of square of first N natural numbers is not more than X in C++
- Python Program for Sum of squares of first n natural numbers

Advertisements