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 e2d6f46 commit a6b20b5Copy full SHA for a6b20b5
algorithms/maths/highest_common_factor.m
@@ -0,0 +1,16 @@
1
+ffunction HCF = mini (x, y)
2
+%This function searches for highest common factor
3
+%It first checks if any of the numbers equal to zero, if so the non zero number is the HCF
4
+%If the numbers are different, you minus the bigger number by the smaller one and this is done by recursion.
5
+ if x==0
6
+ HCF = y;
7
+ elseif y==0
8
+ HCF == x;
9
+ elseif (y == x)
10
+ HCF = x;
11
+ elseif (y>x)
12
+ HCF = mini(y-x,x);
13
+ else
14
+ HCF = mini(x-y,y);
15
+ end
16
+
0 commit comments