From 81d80db93f3024d29500ccac8e8fc2435e41f7b2 Mon Sep 17 00:00:00 2001 From: Kirlos Date: Tue, 29 Oct 2019 21:24:04 +0200 Subject: [PATCH] adding the GCD using c++ --- find the greatest common divisor.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 find the greatest common divisor.cpp diff --git a/find the greatest common divisor.cpp b/find the greatest common divisor.cpp new file mode 100644 index 0000000..af48315 --- /dev/null +++ b/find the greatest common divisor.cpp @@ -0,0 +1,22 @@ +#include + +using namespace std; + +int main() +{ + int x, y, z = 0; + cout << "Enter two numbers : "; + cin >> x >> y; + if(x > y) swap(x,y); + for(int i = x; i > 0; i--) + { + if(x % i == 0 && y % i == 0) + { + z = i; + break; + } + } + if (z == 0) cout << "Impossible"; + else cout << "The GCD is : " << z; + return 0; +}