Untitled
unknown
csharp
3 years ago
1.2 kB
7
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...