Skip to content

Commit 03916df

Browse files
author
Julian
authored
Add negative number support for EuclideanAlg C#
1 parent 7420e4c commit 03916df

File tree

1 file changed

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

1 file changed

+8
-0
lines changed

chapters/fundamental_algorithms/euclidean_algorithm/euclidean.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ namespace Euclidean_Algorithm
269269
{
270270
public static int EuclidSub(int a, int b)
271271
{
272+
// Math.Abs for negative number support
273+
a = Math.Abs(a);
274+
b = Math.Abs(b);
275+
272276
while (a != b)
273277
{
274278
if (a > b)
@@ -282,6 +286,10 @@ namespace Euclidean_Algorithm
282286

283287
public static int EuclidMod(int a, int b)
284288
{
289+
// Math.Abs for negative number support
290+
a = Math.Abs(a);
291+
b = Math.Abs(b);
292+
285293
while (b != 0)
286294
{
287295
var temp = b;

0 commit comments

Comments
 (0)