using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Find_LCM_of_Two_Numbers
{
class Program
{
public static int lcm(int a, int b)
{
int num1, num2;
if (a > b)
{
num1 = a;
num2 = b;
}
else
{
num1 = b;
num2 = a;
}
for (int i = 1; i
<= num2; i++)
{
if ((num1 * i) % num2 == 0)
{
return i * num1;
}
}
return num2;
}
static void Main(string[] args)
{
int num1, num2;
Console.WriteLine("Enter
2 numbers :");
num1 = int.Parse(Console.ReadLine());
num2 = int.Parse(Console.ReadLine());
int result = lcm(num1, num2);
Console.WriteLine("LCM
of {0} and {1} is {2}", num1, num2, result);
Console.Read();
}
}
}
output
No comments:
Post a Comment