- 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
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 ,
12 + 22 = 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 Articles
- Average of Squares of n Natural Numbers?
- Average of first n even natural numbers?
- Python Program for Sum of squares of first n natural numbers
- C++ Program for Sum of squares of first n natural numbers?
- Sum of squares of first n natural numbers in C Program?
- Java Program to calculate Sum of squares of first n natural numbers
- The sum of the squares of three consecutive natural numbers is 149. Find the numbers.
- Find the average of first N natural numbers in C++
- How many natural numbers lie between the squares of 25 and 26?
- Difference between sum of the squares of and square of sum first n natural numbers.
- PHP program to find the average of the first n natural numbers that are even
- Sum of squares of Fibonacci numbers in C++
- Which of the following numbers are squares of even numbers?121,225,256,324,1296,6561,5476,4489, 373758
- Find two natural numbers which differ by 3 and whose squares have the sum 117.
- 8086 program to determine squares of numbers in an array of n numbers
