answersLogoWhite

0

A program to find GCD andLCM of two numbers?

Updated: 8/18/2019
User Avatar

Wiki User

12y ago

Best Answer

// recursive algorithm to return gcd using Euclid's Algorithm

int gcd (int a, int b) {

if (a<0) a= -a;

if (b<0) b= -b;

if (a<b) { int tmp; tmp= a; a= b; b= tmp; }

if (b == 0) return a;

return gcd (b, a%b);

}

// LCM using gcd

int LCM (int a, int b) {

int t;

t = a*b;

if (t<0) t=-t;

return t / gcd (a, b);

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: A program to find GCD andLCM of two numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Shell program for gcd of three given numbers?

write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? check bellow link http://bashscript.blogspot.com/2009/08/gcd-of-more-than-two-numbers.html


Define flowchart and draw flowchart for GCD of two numbers?

pictorial representation of a program is called a flowchart


How do you find the numbers given the gcd and lcm?

if the gcd and lcm are given and one of the numbers are also given,multiply the gcd and lcm and divide them by the given number


How do you find the GCD of two numbers?

use slide


What is pseudo code for GCD of two numbers?

public class GCD { public static void main(String[] args) { //Example how to use this method System.out.println(GCD(15,50)); } //find the greatest common divisor of two numbers public static int GCD(int a, int b){ if (b == 0) return a; return GCD(b, a % b); } } Hope this help to solve you problem.


What is the gcd of 12?

You need at least two numbers to find a GCF.


What is the GCD of 336?

You need at least two numbers to find a GCF.


What is the GCD of 1029?

You need at least two numbers to find something in common.


What is the gcd of 24?

You need at least two numbers to find something in common.


What is 26 GCD?

You need at least two numbers to find something in common.


What is the GCD of 13?

You need at least two numbers to find something in common between them.


To find gcd o two numbers?

You should ask a question here, shouldn't you?