Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Rational
- {
- private int x;
- private int y;
- public Rational(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- public int GetNumerator()
- {
- return this.x;
- }
- public int GetDenom()
- {
- return this.y;
- }
- public bool IsEqual(Rational num)
- {
- if (this.x * num.y == this.y * num.x)
- return true;
- else return false;
- }
- public Rational Multiply(Rational num)
- {
- Rational R = new Rational(this.x * num.x, this.y * num.y);
- return R;
- }
- public Rational Divide(Rational num)
- {
- Rational D = new Rational(this.x* num.y, this.y * num.x);
- return D;
- }
- public override string ToString()
- {
- return string.Format(x + "/" + y);
- }
- }
- class Program
- {
- public static Rational Plus (Rational num,Rational num2)
- {
- int a = num.GetNumerator();
- int b = num.GetDenom(), c = num2.GetNumerator(), d = num2.GetDenom();
- Rational r1 = new Rational(a * d + c * b, a * d + d * a);
- return r1;
- }
- static void Main(string[] args)
- {
- Rational r2 = new Rational(1, 6);
- Rational r1 = new Rational(2, 4);
- Console.WriteLine(Plus(r1, r2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement