Mid From PDF Coding C# Coding Interview

Find gcd and lcm of two numbers?

public int GCD(int a, int b) {

Follow on:

while (b != 0) {

int temp = b;

b = a % b;

a = temp;

return a;

public int LCM(int a, int b) {

return (a / GCD(a, b)) * b;

Explanation:

GCD uses Euclidean algorithm. LCM calculated via LCM(a,b) = (a*b)/GCD(a,b).

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details