
- 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 check if a given number is present in an infinite series or not
To check if a given number is present in an infinite series or not, the PHP code is as follows −
Example
<?php function contains_val($m, $n, $o){ if ($m == $n) return true; if (($n - $m) * $o > 0 && ($n - $m) % $o == 0) return true; return false; } $m = 3; $n = 5; $o = 9; if (contains_val($m, $n, $o)) echo "The number is present in the infinite series"; else echo "The number is not present in the infinite series"; ?>
Output
The number is not present in the infinite series
Above, three variables are defined, and the function is called by passing these three values −
$m = 3; $n = 5; $o = 9;
A function named ‘contains_val’ is defined, that takes these three variables. The first two variables are compared, and if they are equal, ‘true’ is returned. Otherwise, if the different between the first two variables with the product of the third number is greater than 0 and the different between the first two variables modulus the third number is 0, ‘true’ is returned. Otherwise, the function returns false −
function contains_val($m, $n, $o){ if ($m == $n) return true; if (($n - $m) * $o > 0 && ($n - $m) % $o == 0) return true; return false; }
- Related Articles
- Java Program to check if a Float is Infinite or Not a Number(NAN)
- Find if the given number is present in the infinite sequence or not in C++
- PHP program to check if a number is prime or not
- Swift Program to Check if the given number is Perfect number or not
- Golang Program to check a given number is finite or not
- PHP program to check if a year is leap year or not
- Check if a given number is sparse or not in C++
- Check if given number is Emirp Number or not in Python
- Swift Program to Check If a Number is Spy number or not
- Golang program to check if k’th bit is set for a given number or not.
- PHP program to find if a number is present in a given sequence of numbers
- C# Program to check if a number is prime or not
- Python program to check if a number is Prime or not
- Check if a number is in given base or not in C++
- C++ program to Check if a Given Binary Tree is an AVL Tree or Not

Advertisements