public static string ToStringWithIntegerPart(MyFrac f) { var intPart = f.nom / f.denom; f.nom -= f.denom * intPart; return($"({intPart.ToString()}+{f.ToString()})"); }
public static MyFrac GetRGR113LeftSum(int n) { MyFrac res = new MyFrac(1, 3); for (int i = 2; i <= n; i++) { res = Plus(res, new MyFrac(1, (2 * i - 1) * (2 * i + 1))); } return(res); }
public static MyFrac GetRGR115LeftSum(int n) { MyFrac res = new MyFrac(1, 1); for (int i = 2; i <= n; i++) { res = Multiply(res, Minus(new MyFrac(1, 1), new MyFrac(1, i * i))); } return(res); }
static void Main(string[] args) { MyFrac drib1 = new MyFrac(18, -8); MyFrac drib2 = new MyFrac(4, 8); int n = 5; Console.WriteLine($"Дрiб1: " + drib1); Console.WriteLine("Дрiб2: " + drib2); Console.WriteLine("Цiла частина дробу = " + MyFrac.ToStringWithIntegerPart(drib1)); Console.WriteLine("Не цiла частина дробу = " + MyFrac.DoubleValue(drib1)); Console.WriteLine("Додавання = " + MyFrac.Plus(drib1, drib2)); Console.WriteLine("Вiднiмання = " + MyFrac.Minus(drib1, drib2)); Console.WriteLine("Множення = " + MyFrac.Multiply(drib1, drib2)); Console.WriteLine("GetRGR113LeftSum (5)" + MyFrac.GetRGR113LeftSum(n)); Console.ReadKey(); }
public static MyFrac Divide(MyFrac f1, MyFrac f2) { return(new MyFrac(f1.nom * f2.denom, f1.denom * f2.nom)); }
public static MyFrac Multiply(MyFrac f1, MyFrac f2) { return(new MyFrac(f1.nom * f2.nom, f1.denom * f2.denom)); }
public static MyFrac Minus(MyFrac f1, MyFrac f2) { return(new MyFrac(f1.nom * f2.denom - f1.denom * f2.nom, f1.denom * f2.denom)); }
public static double DoubleValue(MyFrac f) { return(f.nom / (double)f.denom); }