Рац. числа - 1 точка
unknown
csharp
2 years ago
1.2 kB
5
Indexable
class Rational { int num; int den; public Rational (int n, int d) { this.num = n; this.den = d; } public void print() { Console.WriteLine("{0}/{1}", this.num, this.den); } public void multi(Rational r) { this.num *= r.num; this.den *= r.den; } public void sum(Rational r) { this.num = this.num * r.den + r.num * this.den; this.den *= r.den; } public void sub(Rational r) { this.num = this.num * r.den - r.num * this.den; this.den *= r.den; } public void dev(Rational r) { this.num *= r.den; this.den *= r.num; } } class Program { static void Main(string[] args) { Rational p = new Rational(1, 2); Rational c = new Rational(1, 3); Console.WriteLine("Действието е умножение."); p.print(); c.print(); p.multi(c); p.print(); } } }
Editor is loading...