Skip to content

Commit

Permalink
Merge pull request #47 from addy0110/main
Browse files Browse the repository at this point in the history
Added program to find HCF of two numbers in C++
  • Loading branch information
anupam-kumar-krishnan authored Oct 5, 2021
2 parents def987e + 7c8e7fb commit 858bca8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Basic Programming/HCFofTwoNum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
using namespace std;

int hcf(int num1, int num2){
if(num1 == 0)
return num2;

if(num2 == 0)
return num1;

if(num1 == num2)
return num1;

if(num1 > num2)
return hcf(num1-num2, num2);

return hcf(num1, num2-num1);
}

int main(){
int num1,num2;
cout<<"Emter 2 numbers : ";
cin>>num1>>num2;
cout<<"HCF of "<<num1<<" and "<<num2<<" : "<<hcf(num1,num2);

return 0;
}

0 comments on commit 858bca8

Please sign in to comment.