Answers for "how to write function in c++ that returns the greatest common divisor between a and b"

C++
6

greatest common divisor c++

// gcd function definition below:
int gcd(int a, int b) {
   if (b == 0)
   return a;
   return gcd(b, a % b);
}

int a = 105, b = 30;
cout<<"GCD of "<< a <<" and "<< b <<" is "<< gcd(a, b);
// output = "GCD of 105 and 30 is 15";
Posted by: Guest on September-16-2020
0

c++ Greatest common divisor

#include <bits/stdc++.h>
using namespace std;
//use c++ 17
int main(){
    long long a,b;
    cin>>a>>b;
    cout<<__gcd(a,b);
	return 0;
}
Posted by: Guest on February-06-2022

Code answers related to "how to write function in c++ that returns the greatest common divisor between a and b"

Browse Popular Code Answers by Language