Bob103

C#_3_(II-17)

Oct 7th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. class Program
  2.     {
  3.         static string div(int a, int b)
  4.         {
  5.             int a_cop = a;
  6.             int b_cop = b;
  7.             while (a > 0 && b > 0)
  8.             {
  9.                 if (a > b)
  10.                 {
  11.                     a %= b;
  12.                 }
  13.                 else
  14.                 {
  15.                     b %= a;
  16.                 }
  17.             }
  18.             int nod = a + b;
  19.            
  20.            if (a_cop > b_cop)
  21.             {
  22.                 return nod.ToString();
  23.             }
  24.             else
  25.                 return string.Format("{0}/{1}", a_cop/nod,b_cop/nod);
  26.         }
  27.  
  28.  
  29.         static void Main()
  30.         {
  31.             Console.Write("Введите a: ");
  32.             int n = Convert.ToInt32(Console.ReadLine());
  33.             Console.Write("Введите b: ");
  34.             int n1 = Convert.ToInt32(Console.ReadLine());
  35.             Console.WriteLine("Дробь a/b ={0} ", div(n, n1));
  36.         }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment