Write a program to find the Average of first N natural number.
Input : 10 Output : 5.5 1+2+3+4+5+6+7+8+9+10 = 5.5 Input : 7 Output : 4.0 1+2+3+4+5+6+7 = 4
Prerequisite : Sum of first n natural numbers.
As discussed in previous post, sum of n natural number n(n+1)/2, we find the Average of n natural number so divide by n is n(n+1)/2*n = (n+1)/2. Here 1 if first term and n is last term.
Time Complexity : O(1)
- Average of first n even natural numbers
- Average of Squares of Natural Numbers
- Find average of two numbers using bit operation
- Program to find sum of first n natural numbers
- Find sum of N-th group of Natural Numbers
- Find if given number is sum of first n natural numbers
- Find m-th summation of first n natural numbers.
- Find maximum N such that the sum of square of first N natural numbers is not more than X
- Find the permutation of first N natural numbers such that sum of i % Pi is maximum possible
- Find the good permutation of first N natural numbers
- Find permutation of first N natural numbers that satisfies the given condition
- Find the count of natural Hexadecimal numbers of size N
- Find the number of sub arrays in the permutation of first N natural numbers such that their median is M
- Find ways an Integer can be expressed as sum of n-th power of unique natural numbers
- Average numbers in array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : jit_t