Write a program using c++ with class GCD for finding Greatest Common Divission (GCD) of an input positive integer a, b.
#include <iostream>
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
int a = 105, b = 30;
cout<<"GCD of "<< a <<" and "<< b <<" is "<< gcd(a, b);
return 0;
}
Comments
Leave a comment