Skip to content

Commit

Permalink
Added GCD Algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Prachi-2001 authored Oct 16, 2021
1 parent e700d25 commit 17d1f97
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Greatest_common_divisor_Algo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Greatest Common Divisor Algorithm in recursive approach

#include<bits/stdc++.h>
using namespace std;

int gcd(int firstNum, int secondNum) {
// firstNum%secondNum = secondNum;
// when secondNum divides completely to the firstNum
// firstNum%secondNum = remainder
if(firstNum%secondNum==0){
return secondNum;
}
return gcd(secondNum,firstNum%secondNum);
}

int main(){
int firstnum , secondnum;
cin>>firstnum>>secondnum;
cout<<gcd(firstnum,secondnum);

return 0;
}

0 comments on commit 17d1f97

Please sign in to comment.