Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online

gmp gcdext function syntax tag tutorial 2013 Donate at flattr Flattr this





Alert! Connect with 10,000 Chating Online. Join Now

Php gmp gcdext () function

Write your php code

 
<?php ?>

Php Result


Your code below



(PHP 4 >= 4.0.4, PHP 5)

gmp_gcdext -- Calculate GCD and multipliers

Syntax

array gmp_gcdext ( resource a, resource b )

Calculates g, s, and t, such that a*s + b*t = g = gcd(a,b), where gcd is the greatest common divisor. Returns an array with respective elements g, s and t.

This function can be used to solve linear Diophantine equations in two variables. These are equations that allow only integer solutions and have the form: a*x + b*y = c. For more information, go to the "Diophantine Equation" page at MathWorld

Example 1. Solving a linear Diophantine equation

<?php
// Solve the equation a*s + b*t = g
// where a = 12, b = 21, g = gcd(12, 21) = 3
$a = gmp_init(12);
$b = gmp_init(21);
$g = gmp_gcd($a, $b);
$r = gmp_gcdext($a, $b);

$check_gcd = (gmp_strval($g) == gmp_strval($r['g']));
$eq_res = gmp_add(gmp_mul($a, $r['s']), gmp_mul($b, $r['t']));
$check_res = (gmp_strval($g) == gmp_strval($eq_res));

if (
$check_gcd && $check_res) {
    
$fmt = "Solution: %d*%d + %d*%d = %d\n";
    
printf($fmt, gmp_strval($a), gmp_strval($r['s']), gmp_strval($b),
    
gmp_strval($r['t']), gmp_strval($r['g']));
} else {
    echo
"Error while solving the equation\n";
}
    
// output: Solution: 12*2 + 21*-1 = 3
?>

Php gmp gcdext Function syntax tag

gmp gcdext php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online



Php gmp gcdext syntax tutorial

php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.


Function index

Variables

Expressions

Operators

Control-Structures

Cookies

Array

Date & Time

Directory function

File

Image

Operators

Form data handling

Mathematics operators

Mail

Php Mysql

Network Functions

Strings

php tutorial guides,functions, classes, code examples and tags for creating simple dynamic site to mysql database driven sites
 
 
Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online