Kod: Zaznacz cały
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace dodawanie_ulamkow_kons
{
class Program
{
static int NWD(int a, int b)
{
int a0 = a;
int b0 = b;
while (b != 0)
{
int c = a % b;
a = b;
b = c;
}
return a;
}
static void Main(string[] args)
{
int a, b, c, d,l,m;
Console.WriteLine("Dodawanie ulamkow a/b+c/d");
Console.WriteLine("Podaj licznik pierwszego ułamka ");
a=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Podaj mianownik pierwszego ułamka ");
b=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Podaj licznik drugiego ułamka ");
c=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Podaj mianownik drugiego ułamka ");
d=Convert.ToInt32(Console.ReadLine());
l = (a * d + c * b)/NWD(b,d);
m = (b * d)/NWD(b,d);
Console.WriteLine("suma tych ułamków wynosi {0}/{1} ",l,m);
Console.ReadKey();
}
}
}