From 61f83228e25de0b3ce1469db71e4d9ba6cfb9ed2 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Thu, 11 Feb 2021 20:18:38 -0500 Subject: [PATCH] Added algorithm to find gcd of two numbers --- src/Algorithms.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Algorithms.rs b/src/Algorithms.rs index a87656c..3762c8b 100644 --- a/src/Algorithms.rs +++ b/src/Algorithms.rs @@ -464,3 +464,18 @@ pub fn swapString(strng: String, first: i32, second: i32) -> String{ } return swappedString; } + +//This function returns the gcd of two numbers +pub fn gcd(in1: i32, in2: i32) -> i32{ + let mut num1 = in1; + let mut num2 = in2; + while((num1 != 0) && (num2 != 0)){ + if(num1 > num2){ + num1 %= num2; + } + else{ + num2 %= num1; + } + } + return num1 | num2; +} \ No newline at end of file