private void btnTongPS_Click(object sender, EventArgs e) { int tusoA = int.Parse(this.tbTuSoa.Text); int mausoA = int.Parse(this.tbmauSoa.Text); int tusoB = int.Parse(this.tbtusob.Text); int mausoB = int.Parse(this.tbmausob.Text); Phanso kq = new Phanso(tusoA, mausoA) + new Phanso(tusoB, mausoB); kq = Phanso.Reduce(kq); this.lbKQ.Text = "Ket qua cong hai phan so:" + kq.tuso + "/" + kq.mauso; }
public static Phanso Reduce(Phanso phanso) { int divisor, numerator, denomnator, reduceNumerator, reduceDenomnator; numerator = phanso.tuso; denomnator = phanso.mauso; divisor = gcd(numerator, denomnator); if (divisor != 1) { reduceNumerator = division(numerator, denomnator); reduceDenomnator = division(numerator, denomnator); return(new Phanso(reduceNumerator, reduceDenomnator)); } else { return(phanso); } }
public static bool operator ==(Phanso a, Phanso b) { Phanso kq = a - b; return(kq.tuso == 0); }