Skip to content

Commit 9c101a0

Browse files
committed
greatest common divisor
1 parent 53ea28f commit 9c101a0

File tree

2 files changed

+31
-0
lines changed
  • Learn_CPP_Programming_Deep_Dive/Section 7 Loops/Program_for_finding_greatest_common_divisor

2 files changed

+31
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
cout<<"Enter the numbers to check for the greatest common divisor"<<endl;
8+
9+
int initial_m, initial_n;
10+
cin>>initial_m>>initial_n;
11+
12+
int n, m;
13+
m = initial_m;
14+
n = initial_n;
15+
16+
while(m!=n)
17+
{
18+
if(m>n)
19+
{
20+
m = m-n;
21+
}
22+
else if(n>m)
23+
{
24+
n = n-m;
25+
}
26+
}
27+
cout<<"The greatest common divisor of the numbers "<<initial_m<<" and "<<initial_n<<" is "<<n<<endl;
28+
29+
return 0;
30+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The content within this repository is my own work produced as a result of comple
88
![Course Info](2023-10-19_17-30-00.png)
99

1010
## IDE used
11+
Visual Studio Code
1112

1213
### About me
1314
* George Calin

0 commit comments

Comments
 (0)