
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP program to find the average of the first n natural numbers that are even
To find the average of the first n natural numbers that are even, the code is as follows −
Example
<?php function even_nums_avg($val) { return $val + 1; } $val = 11; print_r("The average of the first n natural numbers that are even is "); echo(even_nums_avg($val)); ?>
Output
The average of the first n natural numbers that are even is 12
A function named ‘even_nums_avg’ is defined that adds up all the numbers up to a given limit, and divides it by total numbers of values. This is the average of the first few natural numbers. A value is defined, and the function is called by passing this value, which is actually the limit up to which the average of numbers needs to be found. Relevant message is displayed on the console.
- Related Articles
- Average of first n even natural numbers?
- Find the average of first N natural numbers in C++
- PHP program to find the sum of cubes of the first n natural numbers
- PHP program to find the sum of the 5th powers of first n natural numbers
- PHP program to calculate the sum of square of first n natural numbers
- PHP program to find the first ‘n’ numbers that are missing in an array
- 8085 program to find the sum of first n natural numbers
- PHP program to find the sum of first n natural numbers that are divisible by a number ‘x’ or a number ‘y’
- Find the sum of first and even natural numbers.
- Find the mean of first 10 even natural numbers.
- PHP program to find the sum of cubes of natural numbers that are odd
- PHP program to find the sum of the first n natural numbers who are not powers of a specific number ‘k’
- Program to find sum of first n natural numbers in C++
- Find the sum of first $n$ odd natural numbers.
- Swift Program to calculate the sum of first N even numbers

Advertisements