Advertisement
Guest User

Untitled

a guest
Mar 24th, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _10.Calculate_GCD
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("Please enter the 2 numbers for which you want to find GCD");
  14. int a = int.Parse(Console.ReadLine());
  15. int b = int.Parse(Console.ReadLine());
  16. int remainder1 = Math.Max(a,b);
  17. int remainder2 = Math.Min(a, b);
  18. int inter2;
  19.  
  20. while (remainder2 !=0)
  21. {
  22. inter2 = remainder2;
  23. remainder2 = remainder1 % remainder2;
  24. if (remainder2 != 0)
  25. {
  26. remainder1 = inter2;
  27. }
  28. else
  29. {
  30. Console.WriteLine(inter2);
  31. }
  32.  
  33. }
  34.  
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement