Skip to main content

Php prime number program with use of class

Php prime number  program with use of class


<?php


class find_p_number
{
# Function to check single number is Prime or not
static function isPrime($number)
{
# Start temporary number from 2 (1 is not a prime number)
$i = 2;
# 1 is not a prime number
if($number == 1)
return false;
# 2 is the only even prime number
if($number == 2)
return true;
# Check numbers other than 1 and 2
while($i <= sqrt($number))
{
if ($number % $i == 0)
return false;
 
$i++;
}
# If the execution has come to this point, means it is a prime Number :)
return true;
}
# Function to check Prime Numbers between two given numbers
static function betweenTwoNumbers($num1, $num2)
{
$prime_numbers = array();
# Check Prime Numbers between two given numbers
for($num1; $num1<$num2; $num1++)
{
# Check whether the current number is prime or not
if(self::isPrime($num1))
$prime_numbers[] = $num1;
}
# Returns the array of prime numbers between supplied numbers
return array_values(array_unique($prime_numbers));
}
}
 
 
?>


Comments

Popular posts from this blog

Minimum and maximum number with - and + 500 in Mysql and Sql query and Find out table scheema of our database in Mysql and sql query and Find out all table name of our database in Mysql and sql query and Find out current date and time in mysql and sql help of sql query

Minimum and maximum number with - and + 500 in Mysql and Sql query:- syntax:-  SELECT MIN(Used)-500 , max(Used)+500 FROM audit Find out current date and time in mysql and sql help of sql query:- syntax:- SELECT now() Find out database name in Mysql and sql query:- syntax:-  SELECT DATABASE(); Find out all table name of our database in Mysql and sql query:- syntax:- SHOW TABLES; Find out   table scheema   of our database in Mysql and sql query:- syntax:- DESCRIBE <table name>;

My first wordpress plugin | how create wordpress plugin | wordpress plugin tutorial

My first wordpress plugin | how create wordpress plugin | wordpress plugin tutorial <?php /* * Plugin Name: Mydb * Description: A short example showing how to add a taxonomy called Course. * Version: 1.0 * Author: developer.wordpress.org * Author URI: https://wordpress.slack.com/team/aternus */ /* ==============STEP 6================== */ function set_error($value) { echo "<div id='wrap'> <div class='error'> ".$value." </div>      </div>"; } if (isset($_POST['submit']) && isset($_POST['name'])) { if(!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['text']) && !empty($_POST['url']) )  { Mydb_Insert_data($_POST['name'],$_POST['email'],$_POST['text'],$_POST['url']); }else{ set_error("all field are required"); } } function Mydb_Insert...