Answer to Question #285725 in C++ for Murifi

Question #285725

Write a program using c++ with class GCD for finding Greatest Common Divission (GCD) of an input positive integer a, b.

1
Expert's answer
2022-01-09T03:08:50-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment