public static bool operator >(int a, Frac b) { Frac c = new Frac(a, 1); if (c > b) { return(true); } return(false); }
public static bool operator >(Frac a, int b) { Frac c = new Frac(b, 1); if (a > c) { return(true); } return(false); }
public static bool operator >(Frac a, Frac b) { Frac c = a - b; if (c.tu * c.mau > 0) { return(true); } return(false); }
//so sanh hai phan so public static bool operator ==(Frac a, Frac b) { Frac c = a - b; if (c.tu == 0) { return(true); } return(false); }
static void Main(string[] args) { Frac c1 = new Frac { Value = 23 }; Frac c2 = new Frac { Value = 45 }; Console.WriteLine(c1.Value + c2.Value); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("nhap vao so n: "); int n; n = int.Parse(Console.ReadLine()); List <Frac> a = new List <Frac>(); for (int i = 0; i < n; i++) { Console.WriteLine("nhap vao phan so thu " + (i + 1)); Console.Write("Nhap tu so: "); int x = int.Parse(Console.ReadLine()); Console.Write("Nhap mau so: "); int y = int.Parse(Console.ReadLine()); Frac c = new Frac(x, y); a.Add(c); } //sap xep lai List a for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { Frac tg = a[i]; a[i] = a[j]; a[j] = tg; } } } Console.WriteLine("Day da sap xep la: "); foreach (Frac b in a) { Console.Write(b + " "); } Console.WriteLine(); Frac s = new Frac(0, 1); for (int i = 0; i < n; i++) { s = s + a[i]; } Console.WriteLine("Tong la: " + s); }
//thuc hien phep tinh phan so voi so nguyen public static Frac operator +(Frac a, int b) { Frac c = new Frac(b, 1); return(a + c); }