Advertisement
GraionDilach

Euklidész

Nov 7th, 2011
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication11
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int a, b;
  13.             do {
  14.                 Console.WriteLine("Kérem be az első számot:");
  15.                 a = int.Parse(Console.ReadLine());
  16.             }
  17.             while (a < 0);
  18.             do {
  19.                 Console.WriteLine("Kérem be a második számot:");
  20.                 b = int.Parse(Console.ReadLine());
  21.             }
  22.             while (b < 0);
  23.  
  24.             int ae=a, be=b; //Euklidész-variáns
  25.  
  26.             while (ae != be)
  27.             {
  28.                 if (ae > be)
  29.                 {
  30.                     ae = ae - be;
  31.                 }
  32.                 else
  33.                 {
  34.                     be = be - ae;
  35.                 }
  36.  
  37.             }
  38.  
  39.             Console.WriteLine("A legnagyobb közös osztó: " + ae);
  40.  
  41.             int lkt = a / ae;
  42.             lkt = lkt * b;
  43.  
  44.             Console.WriteLine("A legkisebb közös többszörös: " + lkt);
  45.  
  46.         }
  47.     }
  48. }
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement