Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

gcd of two numbers

#include <iostream>
using namespace std;
int gcd(int a , int b)
{
    if(a==0)
    return a;
    if(b==0)
    return b;
    if(a==b)
    return a;
    if(a>b)
    {
        return gcd(a-b,b);
    }
    else
    {
        return gcd(a,b-a);
    }
}
int main()
{
    cout<<gcd(18,24);
    return 0;
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #gcd #numbers
ADD COMMENT
Topic
Name
4+9 =