I’m writing a mixed numeral class and need a quick and easy ‘greatest common divisor’ function. Can anyone give me the code or a link to the code?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m tempted to vote to close — it seems difficult to believe that an implementation would be hard to find, but who knows for sure.
In C++ 17 or newer, you can just
#include <numeric>, and usestd::gcd(and if you care about the gcd, chances are pretty fair that you’ll be interested in thestd::lcmthat was added as well).