vanya

unknown
csharp
2 years ago
2.5 kB
2
Indexable
Never
```using System;

class Fraction
{
public int Numerator { get; set; }
public int Denominator { get; set; }

public Fraction(int numerator, int denominator)
{
Numerator = numerator;
Denominator = denominator;
}

public void Simplify()
{
int gcd = GCD(Numerator, Denominator);
Numerator /= gcd;
Denominator /= gcd;
}

{
int numerator = Numerator * other.Denominator + other.Numerator * Denominator;
int denominator = Denominator * other.Denominator;
Fraction result = new Fraction(numerator, denominator);
result.Simplify();
return result;
}

public Fraction Multiply(Fraction other)
{
int numerator = Numerator * other.Numerator;
int denominator = Denominator * other.Denominator;
Fraction result = new Fraction(numerator, denominator);
result.Simplify();
return result;
}

public override string ToString()
{
return Numerator + "/" + Denominator;
}

private int GCD(int a, int b)
{
while (a != b)
{
if (a > b)
{
a = a - b;
}
else
{
b = b - a;
}
}
return a;
}
}

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the numerator of the first fraction:");

Console.WriteLine("Enter the denominator of the first fraction:");

Console.WriteLine("Enter the numerator of the second fraction:");

Console.WriteLine("Enter the denominator of the second fraction:");

Fraction a = new Fraction(aNumerator, aDenominator);
Fraction b = new Fraction(bNumerator, bDenominator);

a.Simplify();
Console.WriteLine("Fraction a is: " + a);

b.Simplify();
Console.WriteLine("Fraction b is: " + b);