Skip to content

Commit 8843c75

Browse files
authored
Merge pull request #22 from A9ine/master
Create highest_common_factor.m
2 parents c905169 + a6b20b5 commit 8843c75

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)