- 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 even numbers till a given even number?

To find the average of even numbers till a given even number, we will add all the even number till the given number and t count the number of even numbers. Then divide the sum by the number of even numbers.

## Example

Average of even numbers till 10 is 6 i.e.

2 + 4 + 6 + 8 + 10 = 30 => 30/ 5 = 6

There are two methods for calculating the average of even number till n which is an even number.

- Using Loops
- Using Formula

## Program to find the average of even number till n using loops

To calculate the average of even numbers till n, we will add all even numbers till n and then divide in by the number of even number till than.

Program to calculate the average of even natural numbers till n −

## Example Code

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

## Output

The average of even numbers till 14 is 8.000000

## Program to find the average of even numbers till n using Formula

To calculate the average of even numbers till n we can use a mathematical formula (n+2)/2 where n is an even number which is the given condition in our problem.

Program to calculate the average of n even natural numbers −

## Example Code

#include <stdio.h> int main() { int n = 15; float average = (n+2)/2; printf("The average of even numbers till %d is %f",n, average); return 0; }

## Output

The average of even numbers till 14 is 8.000000

- Related Articles
- Average of odd numbers till a given odd number?
- Average of first n even natural numbers?
- Swift Program to Find Sum of Even Fibonacci Terms Till number N
- Java Program to Find Even Sum of Fibonacci Series till number N
- Fetch Numbers with Even Number of Digits JavaScript
- XOR of numbers that appeared even number of times in given Range in C++
- State whether the following statements are True or False:(a) The sum of three odd numbers is even.(b) The sum of two odd numbers and one even number is even.(c) The product of three odd numbers is odd.(d) If an even number is divided by 2, the quotient is always odd.(e) All prime numbers are odd.(f) Prime numbers do not have any factors.(g) Sum of two prime numbers is always even.(h) 2 is the only even prime number.(i) All even numbers are composite numbers.(j) The product of two even numbers is always even.
- Find Numbers with Even Number of Digits in Python
- 8086 program to find sum of Even numbers in a given series
- PHP program to find the average of the first n natural numbers that are even
- Even numbers at even index and odd numbers at odd index in C++
- The sum of three consecutive even number is 96 . Find the numbers
- C++ Queries on Probability of Even or Odd Number in Given Ranges
- What are even and odd numbers?
- Do all even numbers are composite?