Added functions to determine the gcd of 2 nums

This commit is contained in:
2021-02-07 12:42:27 -05:00
parent 409925f924
commit 32a937f626

View File

@@ -705,6 +705,40 @@ namespace mee{
//Return the proper number. The location counter is 1 off of the subscript //Return the proper number. The location counter is 1 off of the subscript
return fibNums[(fibLoc - 1) % 3]; return fibNums[(fibLoc - 1) % 3];
} }
//This function returns the GCD of the two numbers sent to it
public static int GCD(int num1, int num2){
while((num1 != 0) && (num2 != 0)){
if(num1 > num2){
num1 %= num2;
}
else{
num2 %= num1;
}
}
return num1 | num2;
}
public static long GCD(long num1, long num2){
while((num1 != 0) && (num2 != 0)){
if(num1 > num2){
num1 %= num2;
}
else{
num2 %= num1;
}
}
return num1 | num2;
}
public static BigInteger GCD(BigInteger num1, BigInteger num2){
while((num1 != 0) && (num2 != 0)){
if(num1 > num2){
num1 %= num2;
}
else{
num2 %= num1;
}
}
return num1 | num2;
}
//This function return sht enumber of times the character occurs in the string //This function return sht enumber of times the character occurs in the string
public static long FindNumOccurrence(string str, char c){ public static long FindNumOccurrence(string str, char c){
return str.Count(ch => ch == c); return str.Count(ch => ch == c);