Skip to content

Commit 36fde45

Browse files
committed
Adding javascript and c to euclidean algorithm
1 parent 298be35 commit 36fde45

File tree

1 file changed

+82
-0
lines changed
  • chapters/fundamental_algorithms/euclidean_algorithm

1 file changed

+82
-0
lines changed

chapters/fundamental_algorithms/euclidean_algorithm/euclidean.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,85 @@ int main(){
114114
}
115115

116116
```
117+
118+
### C
119+
```c
120+
#include <stdio.h>
121+
#include <math.h>
122+
123+
int euclid_mod(int a, int b){
124+
125+
int temp;
126+
while (b != 0){
127+
temp = b;
128+
b = a%b;
129+
a = temp;
130+
}
131+
132+
return a;
133+
}
134+
135+
int euclid_sub(int a, int b){
136+
137+
while (a != b){
138+
if (a > b){
139+
a = a - b;
140+
}
141+
else{
142+
b = b - a;
143+
}
144+
}
145+
146+
return a;
147+
}
148+
149+
int main(){
150+
151+
int check = euclid_mod(64*67, 64*81);
152+
int check2 = euclid_sub(128*12, 128*77);
153+
154+
printf("%d\n", check);
155+
printf("%d\n", check2);
156+
}
157+
158+
```
159+
160+
### JavaScript
161+
162+
```html
163+
<!DOCTYPE html>
164+
<html>
165+
<body>
166+
<script>
167+
function euclid_mod(a, b){
168+
169+
var temp;
170+
while (b != 0){
171+
temp = b;
172+
b = a%b;
173+
a = temp;
174+
}
175+
176+
return a;
177+
}
178+
179+
function euclid_sub(a, b){
180+
181+
while (a != b){
182+
if (a > b){
183+
a = a - b;
184+
}
185+
else{
186+
b = b - a;
187+
}
188+
}
189+
190+
return a;
191+
}
192+
193+
document.write(euclid_mod(64*67, 64*81) + "<br>");
194+
document.write(euclid_sub(128*12, 128*77) + "<br>");
195+
</script>
196+
</body>
197+
</html>
198+
```

0 commit comments

Comments
 (0)