Skip to content

Commit e3fe430

Browse files
authored
Create Find_HCF.cpp
It is program in which we can find HCF of N integers.
1 parent aaf6a4c commit e3fe430

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Maths/Find_HCF.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int HCF(int a, int b) {
5+
return (b == 0) ? a : HCF(b, a%b);
6+
}
7+
8+
int main() {
9+
10+
int n;
11+
cin >> n;
12+
13+
int nums[n];
14+
15+
int hcf = 1;
16+
17+
for(int i = 0; i < n ; i++) {
18+
cin >> nums[i];
19+
hcf = HCF(hcf, nums[i]);
20+
}
21+
22+
cout << hcf << endl;
23+
return 0;
24+
25+
}

0 commit comments

Comments
 (0)