public static string convertFrac(long[,] lst) { if (lst.GetLength(0) <= 0) { return(string.Empty); } long[] denominators = new long[lst.GetLength(0)]; for (int i = 0; i < denominators.Length; i++) { denominators[i] = lst[i, 1]; } long lcm = Fracts.lcm(denominators); long[,] answer = new long[lst.GetLength(0), 2]; for (int i = 0; i < lst.GetLength(0); i++) { long multiplier = lcm / lst[i, 1]; answer[i, 0] = lst[i, 0] * multiplier; answer[i, 1] = lst[i, 1] * multiplier; } return(Fracts.Print2DArray(answer)); }
static void Main(string[] args) { Console.WriteLine("Hello, World!"); //Console.WriteLine("Answer = {0}", Fracts.lcm(new int[] { 1, 2, 3, 4, 5, 10, 20, 35 })); long[,] lst = new long[, ] { { 1, 2 }, { 1, 3 }, { 1, 4 } }; Console.WriteLine(String.Format("{0} => {1}", Fracts.Print2DArray(lst), Fracts.convertFrac(lst))); lst = new long[, ] { { 69, 130 }, { 87, 1310 }, { 3, 4 } }; Console.WriteLine(String.Format("{0} => {1}", Fracts.Print2DArray(lst), Fracts.convertFrac(lst))); }