
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

C# Online Compiler Learn Python
Main.cs Output
// Online C# Editor for free // Write, Edit and Run your C# code using C# Online Compiler
//Rivas, Joy B. //BSIT III- //Write a program that given two numbers finds their greatest common divisor (GCD) and their least common multiple (LCM). You may use the formula LCM(a, b) = |a*b| / GCD(a, b).
using System;
public class HelloWorld { public static void Main(string[] args) { Console.Write("Please enter the first number: "); int num1 = int.Parse(Console.ReadLine()); Console.Write("Please enter the second number: "); int num2 = int.Parse(Console.ReadLine());
int gcd = GetGCD(num1, num2); int lcm = GetLCM(num1, num2);
Console.WriteLine("Greatest Common Divisor ({ ,4} and {1,4}) = {2,6}", num1, num2, gcd); Console.WriteLine("Least Common Multiple ({0,4} and {1,4}) = {2,6}", num1, num2, lcm);
int GetGCD(int first, int second) { while (first != second) { if (first > second) first = first - second;
if (second > first) second = second - first; } return first; }
int GetLCM(int first, int second) { return (first * second) / GetGCD(first, second); } } }
Run