File tree 1 file changed +50
-0
lines changed
chapters/fundamental_algorithms/euclidean_algorithm
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -227,3 +227,53 @@ def euclid_sub(a, b):
227
227
print euclid_mod(64 * 67 , 64 * 81 )
228
228
print euclid_sub(128 * 12 , 128 * 77 )
229
229
```
230
+
231
+ ### C#
232
+
233
+ ``` cs
234
+ // submitted by Julian Schacher
235
+ using System ;
236
+
237
+ namespace Euclidean_Algorithm
238
+ {
239
+ class Program
240
+ {
241
+ static void Main (string [] args )
242
+ {
243
+ int check = Algorithms .EuclidMod (64 * 67 , 64 * 81 );
244
+ int check2 = Algorithms .EuclidSub (128 * 12 , 128 * 77 );
245
+
246
+ Console .WriteLine (check );
247
+ Console .WriteLine (check2 );
248
+ }
249
+ }
250
+
251
+ public static class Algorithms
252
+ {
253
+ public static int EuclidSub (int a , int b )
254
+ {
255
+ while (a != b )
256
+ {
257
+ if (a > b )
258
+ a = a - b ;
259
+ else
260
+ b = b - a ;
261
+ }
262
+
263
+ return a ;
264
+ }
265
+
266
+ public static int EuclidMod (int a , int b )
267
+ {
268
+ while (b != 0 )
269
+ {
270
+ var temp = b ;
271
+ b = a % b ;
272
+ a = temp ;
273
+ }
274
+
275
+ return a ;
276
+ }
277
+ }
278
+ }
279
+ ```
You can’t perform that action at this time.
0 commit comments