

- 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
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 Questions & Answers
- 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
- 8085 program to find the sum of first n natural numbers
- PHP program to calculate the sum of square of first n natural numbers
- PHP program to find the sum of cubes of natural numbers that are odd
- Find the good permutation of first N natural numbers C++
- Average of Squares of 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++
- 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?
Advertisements