- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

To find the average of the first n natural numbers that are even, the code is as follows −

<?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)); ?>

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 Questions & Answers
- Average of first n even natural numbers?
- 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
- 8085 program to find the sum of first n natural numbers
- PHP program to find the sum of cubes of natural numbers that are odd
- 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
- Find permutation of first N natural numbers that satisfies the given condition in C++
- Average of Squares of n Natural Numbers?
- Program to find sum of first n natural numbers in C++
- Java program to find the sum of n natural numbers
- PHP program to find the sum of the first n natural numbers who are not powers of a specific number ‘k’
- C Program for the cube 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’
- 8086 program to find average of n numbers

Advertisements