![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 n Natural Numbers?
Given a number n, we need to find the average of the square of natural Numbers till n. For this we will first The squares of all the numbers till n. then we will add all these squares and divide them by the number n.
Input 3 Output 4.666667
Explanation
12 + 22 + 32 = 1 + 4 + 9 = 14 14/3 = 4.666667
Example
#include<iostream> using namespace std; int main() { long n , i, sum=0 ,d; n=3; for(i=1;i<=n;++i) { d=i*i; sum+=d; } cout<<sum/n; return 0; }
Advertisements