#include<stdio.h>
#include<conio.h>
int find_gcd(int,int);
int find_lcm(int,int);
int main(){
int num1,num2,gcd,lcm;
clrscr();
printf("\nEnter two numbers:\n ");
scanf("%d %d",&num1,&num2);
gcd=find_gcd(num1,num2);
printf("\n\nGCD of %d and %d is: %d\n\n",num1,num2,gcd);
if(num1>num2)
lcm = find_lcm(num1,num2);
else
lcm = find_lcm(num2,num1);
printf("\n\nLCM of %d and %d is: %d\n\n",num1,num2,lcm);
return 0;
}
int find_gcd(int n1,int n2){
while(n1!=n2){
if(n1>n2)
return find_gcd(n1-n2,n2);
else
return find_gcd(n1,n2-n1);
}
return x;
}
pictorial representation of a program is called a flowchart
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.
The following function will return the GCD or LCM of two arguments (x and y) depending on the value of the fct argument (GCD or LCM). enum FUNC {GCD, LCM}; int gcd_or_lcm(FUNC fct, int x, int y) { int result = 0; switch (fct) { case (GCD): result = gcd (x, y); break; case (LCM): result = lcm (x, y); break; } return result; }
algorithm GCD (a, b) is:while (a b) doif a > b then a := a - b else b := b - aend whilereturn a
One way to find the GCD (Greatest Common Divisor) of two numbers is Euclid's method. The following program demostrates this, without using recursion. The third number printed is the GCD of the first two. The highlighted lines are the core of the algorithm.#include int GcdByEuclid (int a, int b) {if (a < 0 b < 0) return -1;while (a > 0 && b > 0) if (a > b) a -= b; else b -= a;if (a == 0) return b; else return a;}int main (int argc, char *argv[]) {int a, b;if (argc < 3) {fprintf (stderr, "Usage: gcd a b\n");return 1;}a = atoi(argv[1]);b = atoi(argv[2]);printf ("%d %d %d", a, b, GcdByEuclid (a, b));return 0;}
use slide
You need at least two numbers to find a GCF.
You need at least two numbers to find a GCF.
You need at least two numbers to find something in common.
You need at least two numbers to find something in common.
You need at least two numbers to find something in common.
Any two numbers who are relatively prime will workSo look at 9 and 4. Neither is prime and their GCD is 1.You must need two numbers with NO other factors in common.
You should ask a question here, shouldn't you?
You need at least two numbers to find something in common between them.
The GCD is 2.
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
The greatest common denominator (GCD) refers to a denominator that is COMMON to two or more numbers. You have only one number in the question! The greatest denominator of any number is itself.