- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion

# Sum of square-sums of first n natural numbers

The sum of square-sums of the first n natural numbers is finding the sum of sum of squares upto n terms. This series finds the sum of each number upto n, and adds this sums to a sum variable.

The sum of square-sum of first 4 natural numbers is −

sum = (1^{2}) + (1^{2} + 2^{2} ) + (1^{2} + 2^{2} + 3^{2}) + (1^{2} + 2^{2} + 3^{2} + 4^{2} ) = 1 + 5 + 14 + 30 = 50

There are two methods to find the sum of square-sum of first n natural numbers.

**1) Using the for loop.**

In this method, we will Loop through to every number from 1 to N and find the square sum and then add this square sum to a sum variable. this method requires an iterations for n numbers, so it would be e time consuming for greater numbers.

## Example

#include <stdio.h> int main() { int n = 6; int sum = 0; for (int i = 1; i <= n; i++) sum += ((i * (i + 1) * (2 * i + 1)) / 6); printf("The square-sum of first %d natural number is %d",n,sum); return 0; }

## Output

The square-sum of first 6 natural number is 196

**2) Using Mathematical formula**−

Based on finding the nth term and and general formula for the sequence a mathematical formula is derived to find the sum. the formula to find some of square sums of first n natural number is sum = n*(n+1)*(n+1)*(n+2)/12

Based on this formula we can make a program to find the sum,

## Example

#include <stdio.h> int main() { int n = 6; int sum = (n*(n+1)*(n+1)*(n+2))/12; printf("The square-sum of first %d natural number is %d",n,sum); return 0; }

## Output

The square-sum of first 6 natural number is 196

- Related Articles
- Difference between sum of the squares of and square of sum first n natural numbers.
- PHP program to calculate the sum of square of first n natural numbers
- Sum of sum of first n natural numbers in C++
- Sum of square of first n odd numbers
- Sum of first n natural numbers in C Program
- Find the sum of first $n$ odd natural numbers.
- Python Program for 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?
- Java Program to cube sum of first n natural numbers
- Finding sum of first n natural numbers in PL/SQL
- Python Program for Sum of squares of first n natural numbers
- Sum of squares of first n natural numbers in C Program?
- C++ Program for Sum of squares of first n natural numbers?
- Java Program to Display Numbers and Sum of First N Natural Numbers