Write C# program to find LCM of any two numbers


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.

techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. public class csharpExercise
  7. {
  8. static void Main(string[] args)
  9. {
  10. int num1, num2, x, y, lcm = 0;
  11. Console.Write("Enter the First Number : ");
  12. num1 = int.Parse(Console.ReadLine());
  13. Console.Write("Enter the Second Number : ");
  14. num2 = int.Parse(Console.ReadLine());
  15. x = num1;
  16. y = num2;
  17. while (num1 != num2)
  18. {
  19. if (num1 > num2)
  20. {
  21. num1 = num1 - num2;
  22. }
  23. else
  24. {
  25. num2 = num2 - num1;
  26. }
  27. }
  28. lcm = (x * y) / num1;
  29. Console.Write("Least Common Multiple is : " + lcm);
  30.  
  31. Console.ReadLine();
  32. }
  33. }

Result

C# language techstudy

     





Related Topics




Popular Posts