- 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

# Average of Squares of Natural Numbers?

The average of the square of Natural Number is calculated by adding all the squares up to n natural numbers and then dividing it by the number.

## Sample

Average of square of first 2 natural numbers is 2.5 ,

1^{2} + 2^{2} = 5 => 5/2 = 2.5.

There are two methods for calculating this is programming −

- Using Loops
- Using Formula

**Calculating average of square of natural numbers using loops**

This logic works by finding the squares of all natural numbers. By loop from 1 to n finding square of each and adding to the sum variable. Then dividing this sum by n.

Program to find the sum of squares of natural numbers −

## Example Code

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

## Output

The average of the square of 2 natural numbers is 2.500000

**Calculating average of square of natural numbers using formula.**

There are mathematical formulas to make calculations easy. For calculating the sum of squares of natural numbers the formula is ‘ n*(n+1)*((2*n)+1)/6’ diving this by the number n gives the formula : ‘ (n+1)*((2*n)+1)/6’.

Program to find the sum of squares of natural numbers −

## Example Code

#include <stdio.h> int main() { int n = 2; float average = ((n+1)*((2*n)+1)/6); printf("The average of the square of %d natural numbers is %f", n,average); return 0; }

## Output

The average of the square of 2 natural numbers is 2.500000

- Related Questions & Answers
- Average of Squares of n Natural Numbers?
- Average of first n even natural numbers?
- C++ Program for Sum of squares of first n natural numbers?
- Sum of squares of first n natural numbers in C Program?
- Python Program for Sum of squares of first n natural numbers
- Java Program to calculate Sum of squares of first n natural numbers
- Find the average of first N natural numbers in C++
- Difference between sum of the squares of and square of sum first n natural numbers.
- Sum of squares of Fibonacci numbers in C++
- PHP program to find the average of the first n natural numbers that are even
- Average of a stream of numbers in C++
- Sum of square-sums of first n natural numbers
- 8086 program to determine squares of numbers in an array of n numbers
- Average of first n odd naturals numbers?
- C++ Program to Calculate Sum of Natural Numbers