
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Average of first n even natural numbers?
Average or mean of n even natural number is the sum of numbers divided by the numbers.
You can calculate this by two methods &minus
Find the sum of n even natural numbers and divide it by number, Using loop.
- Find the sum of n even natural numbers and divide it by number, Using formula.
Method 1 - Using Loop
Find the sum of even natural numbers using a loop that counts up to the number we want the sum. Then we will divide it by n.
Example Code
#include <stdio.h> int main(void) { int n = 5; int sum = 0; int average = 0; for (int i = 1; i <= n ; i++) { sum += (i*2); } average = sum / n; printf("The average of %d even natural numbers is %d", n,average); return 0; }
Output
The average of 5 even natural numbers is 6
Method 1 − Using Formula
Find the sum of even natural numbers using a mathematical Formula that directly calculates the average.
The formula is (n + 1) = n*(n + 1 )/ n..
Example Code
#include <stdio.h> int main(void) { int n = 5; int average = n+1 ; printf("The average of %d even natural numbers is %d", n,average); return 0; }
Output
The average of 5 even natural numbers is 6
The second method that uses formula is better because in cases with larger value of n, the loop will run n time will increase the time.
- Related Articles
- PHP program to find the average of the first n natural numbers that are even
- Find the average of first N natural numbers in C++
- Average of Squares of n Natural Numbers?
- Find the sum of first and even natural numbers.
- Find the mean of first 10 even natural numbers.
- Average of first n odd naturals numbers?
- Sum of square-sums of first n natural numbers
- Sum of first n natural numbers in C Program
- Find the sum of first $n$ odd natural numbers.
- Average of Squares of Natural Numbers?
- Sum of sum of first n natural numbers in C++
- Java Program to Display Numbers and Sum of First N Natural Numbers
- Average of even numbers till a given even number?
- Python Program for cube sum of first n natural numbers
- C++ Program for cube sum of first n natural numbers?

Advertisements