- Related Questions & Answers
- Sum of squares of first n natural numbers in C Program?
- C++ Program for Sum of squares of first n natural numbers?
- Python Program for Sum of squares of first n natural numbers
- Java Program to calculate Sum of squares of first n natural numbers
- Difference between sum of the squares of and square of sum first n natural numbers.
- Sum of first n natural numbers in C Program
- Minimize the sum of squares of sum of N/2 paired formed by N numbers in C++
- Sum of sum of first n natural numbers in C++
- Sum of the first N Prime numbers
- Average of first n even natural numbers?
- C Program for the cube sum of first n natural numbers?
- C Program for cube sum of first n natural numbers?
- C++ Program for cube sum of first n natural numbers?
- Program to find sum of first n natural numbers in C++
- Program for cube sum of first n natural numbers in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

The sum of squares of the first n even numbers means that, we first find the square and add all them to give the sum.

There are two methods to find the sum of squares of the first n even number

We can use loops to iterate from 1 to n increase number by 1 each time find the square and add it to the sum variable −

#include <iostream> using namespace std; int main() { int sum = 0, n =12; for (int i = 1; i <= n; i++) sum += (2 * i) * (2 * i); cout <<"Sum of first "<<n<<" natural numbers is "<<sum; return 0; }

Sum of first 12 natural numbers is 2600

The complexity of this program increase by order 0(n). So, for big values of n, code takes time.

To deal with this problem a mathematical formula is derived which is Sum of even natural number is 2n(n+1)(2n+1)/3

#include <iostream> using namespace std; int main() { int n = 12; int sum = (2*n*(n+1)*(2*n+1))/3; cout <<"Sum of first "<<n<<" natural numbers is "<<sum; return 0; }

Sum of first 12 natural numbers is 2600

Advertisements