mirror of
https://bitbucket.org/Mattrixwv/csclasses.git
synced 2025-12-06 18:23:58 -05:00
Added functions to determine the gcd of 2 nums
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user