static void Main(string[] args) { PhanSo ps1 = new PhanSo(1, 4); PhanSo ps2 = new PhanSo(4, 5); Console.WriteLine("phan so: {0},{1} sau khi rut gon : {2}, {3}", ps1.toString(), ps2.toString(), ps1.rutGonPS().toString(), ps2.rutGonPS().toString()); Console.WriteLine("phan so: {0} + {1} = {2}", ps1.toString(), ps2.toString(), (ps1 + ps2).rutGonPS().toString()); Console.WriteLine("phan so: {0} > {1}", (ps1 > ps2) ? ps1.rutGonPS().toString() : ps2.rutGonPS().toString(), (ps2 < ps1) ? ps2.rutGonPS().toString() : ps1.rutGonPS().toString()); Console.WriteLine("Phan so: {0} + 1 = {1}", ps1.rutGonPS().toString(), (+ps1).rutGonPS().toString()); Console.ReadKey(); }
public PhanSo rutGonPS() { int j, i, ucln = 1; PhanSo xy; j = (_tuSo < _mauSo) ? _tuSo : _mauSo; for (i = 1; i <= j; i++) { if (_tuSo % i == 0 && _mauSo % i == 0) { ucln = i; } } xy = new PhanSo(_tuSo / ucln, _mauSo / ucln); return(xy); }
public PhanSo getThuong(PhanSo ps) { PhanSo xy = new PhanSo(_tuSo * ps._mauSo, _mauSo * ps._tuSo); return(xy); }
public PhanSo getHieu(PhanSo ps) { PhanSo xy = new PhanSo(_tuSo * ps._mauSo - _mauSo * ps._tuSo, _mauSo * ps._mauSo); return(xy); }