From 4c8a20720527dfb46398305993de0801058f6488 Mon Sep 17 00:00:00 2001 From: Piyush Raj <63510532+piyushraj707@users.noreply.github.com> Date: Sun, 5 Jun 2022 21:53:48 +0530 Subject: [PATCH] Create gcd_theorem.cpp This program finds HCF of two numbers. The logic behind the code is that HCF of 'a' and 'b' is same as 'a-b' and 'b'. And when one of the numbers is zero the other one is automatically the HCF of the two. --- CPP/gcd_theorem.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 CPP/gcd_theorem.cpp diff --git a/CPP/gcd_theorem.cpp b/CPP/gcd_theorem.cpp new file mode 100644 index 0000000..3d223c6 --- /dev/null +++ b/CPP/gcd_theorem.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; + +int GCD(int a, int b) +{ + if (!b) //if b==0 + return a; + else + return GCD(b,a%b); +} + +int main() +{ + cout<<"Provide two number (separated by space) whose HCF is to be found: "; + int a,b; + cin>>a>>b; + cout<