We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6b7eef8 commit e2a5364Copy full SHA for e2a5364
gcd.cpp
@@ -0,0 +1,25 @@
1
+#include <iostream>
2
+using namespace std;
3
+
4
+int main() {
5
+ int n1, n2, hcf;
6
+ cout << "Enter two numbers: ";
7
+ cin >> n1 >> n2;
8
9
+ // swapping variables n1 and n2 if n2 is greater than n1.
10
+ if ( n2 > n1) {
11
+ int temp = n2;
12
+ n2 = n1;
13
+ n1 = temp;
14
+ }
15
16
+ for (int i = 1; i <= n2; ++i) {
17
+ if (n1 % i == 0 && n2 % i ==0) {
18
+ hcf = i;
19
20
21
22
+ cout << "HCF = " << hcf;
23
24
+ return 0;
25
+}
0 commit comments