gcd
viewed 3284 times and licensed 47 times
Compute the greatest common divisor of two values.
Excel: GCD
Controller:
CodeCogs
Interface
#include <codecogs/maths/combinatorics/arithmetic/gcd.h>
using namespace Maths::Arithmetic;
| double | gcd (double a, double b)
Compute the greatest common divisor of two values.
<span align="right" style="background-color:99FF99"><strong>Excel: GCD</strong></span> |
These functions are available for Microsoft Excel (
Login to download):
| Real | cc_gcd (Real a, Real b) |
Use the following HTML code to embed the calculators within other websites:
| Name | HTML Code |
|---|
gcd
Compute the greatest common divisor of two values.
Excel: GCD | |
Gcd
Calculate the greatest common divisor of two values. This function
is equivalent to the Microsoft Excel function
GCD . One divides
every number evenly. If either argument is zero, the other argument
is returned.
This function is non-recursive so will not cause stack problems
with exremely large values.
Example 1
#include <iostream>
#include <codecogs/maths/arithmetic/gcd.h>
int main(int argc, char *argv[])
{
double a=5.0, b=2.0;
std::cout<<"gcd("<<a<<", "<<b<<")="<<Maths::Arithmetic::gcd(a, b)<<std::endl;
a=24.0, b=36.0;
std::cout<<"gcd("<<a<<", "<<b<<")="<<Maths::Arithmetic::gcd(a, b)<<std::endl;
a=7.0, b=1.0;
std::cout<<"gcd("<<a<<", "<<b<<")="<<Maths::Arithmetic::gcd(a, b)<<std::endl;
a=5.0, b=0.0;
std::cout<<"gcd("<<a<<", "<<b<<")="<<Maths::Arithmetic::gcd(a, b)<<std::endl;
return 0;
}
Output:
gcd(5, 2)=1
gcd(24, 36)=12
gcd(7, 1)=1
gcd(5, 0)=5
Parameters
| a | The first value. |
| b | The second value. |
Returns
- The greatest common divisor of the two values.
Authors
- James Warren (July 2005)
Source Code
Source code is available when you agree to a GP Licence or buy a Commercial Licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.
You must login to leave a messge