Hi Guy’s , Here is the article to display HCF and LCM in c#.
LCM stands for Lowest Common Multiple and HCF stands for Highest Common Factor.
about LCM and HCF we alrady studied in 8th standard .Let’s see c# program for lcm and hcf. Find GCD in C# programming.
Code Explanation :
Here, i have taken seven integer variables n1,n2,temp,hcf,lcm,a,b;.
Console.Write(“Enter Two Numbers : “); “Enter Two Numbers” that display into output screen.
n1 = int.Parse(Console.ReadLine()); at here i am using Console.ReadLine method so whatever we enter that accept into string and after applying int.parse typecasting that convert
into integer and store value into n1 the same things with n2.
a = n1 that means n1 value go to a.
b = n2 that means n2 value go to b.
while b != 0: if b value not equal to zero then while to continue.
temp = b that means b value go to temp.
b = a%b that means a%b value go to b.
temp = a that means a value go to temp. while loop continue until condition false.
when while loop condition false control out from while loop
hcf = a that means a value go to hcf
lcm = n1 * n2 / hcf , after performing right side arithmatic calculation,the value move to lcm.
print(“Highest Common Factor = “,hcf)
that print Highest Common Factor = into output screen with hcf value.
print(“Lowest Common Multiple = “,lcm)
that print Lowest Common Multiple = into output screen with lcm value.