- 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 squares of the first n even numbers in C Program

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

## Using Loops

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 −

### Example

#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; }

### Output

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.

## Using Mathematical formula

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

### Example

#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; }

### Output

Sum of first 12 natural numbers is 2600

- Related Articles
- 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
- Swift Program to calculate the sum of first N even 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++
- C Program for the cube sum of first n natural numbers?
- Sum of sum of first n natural numbers in C++
- C++ Program for cube sum of first n natural numbers?
- C Program for cube sum of first n natural numbers?
- Program for cube sum of first n natural numbers in C++
- Program to find sum of first n natural numbers in C++
- The sum of the squares of two consecutive even numbers is 340. Find the numbers.

Advertisements