Question

C++ Program to find Greatest common Factor (GCF) and Least Common Multiple (LCM) of a number...

C++ Program to find Greatest common Factor (GCF) and Least Common Multiple (LCM) of a number

c++

Homework Answers

Answer #1

#include<iostream>

using namespace std;

int main()
{
int p, q, n1, n2, t, gcf, lcm;
cout<<"Enter the two numbers : ";
cin >> n1 >> n2; // read the two numbers
p = n1;
q = n2;
while (q != 0) // calculate gcf
{
t = q;
q = p % q;
p = t;
}
gcf = p;
lcm = (n1 * n2) / gcf; // calculate lcm
cout << "GCF of two numbers " << n1 <<" and " << n2 << " is : " << gcf << endl; // print gcf
cout << "LCM of two numbers "<< n1 <<" and " << n2 << " is : " << lcm; // print lcm

return 0;
}

OUTPUT :

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a C++ program to find least common multiple (LCM) of two, three and four integer...
Write a C++ program to find least common multiple (LCM) of two, three and four integer values. The integer values are entered from the keyboard and the outputs are printed to the console. The LCM of two, three and four integer values are computed using Prime factorization method. You have to use arrays to hold input values and use functions/methods to get data from the keyboard, display output to the console, calculate LCM using Prime factorization method. Your program should...
Find the greatest common factor applying Euclidean Algorithm: 29448, 59220
Find the greatest common factor applying Euclidean Algorithm: 29448, 59220
Write Java program Lab42.java which takes as input two positive integers m and n and computes...
Write Java program Lab42.java which takes as input two positive integers m and n and computes their least common multiple by calling method lcm(m,n), which in turn calls recursive method gcd(m,n) computing the greatest common divisor of m and n. Recall, that lcm(m,n) can be defined as quotient of m * n and gcd(m,n).
C CODE PLZ! All instructions are in sections of code #include <stdio.h> /* TODO: Define 3...
C CODE PLZ! All instructions are in sections of code #include <stdio.h> /* TODO: Define 3 functions input, gcd and lcm in such a way that the main function below compiles correctly and has the correct behavior. The input function prompts the user to enter a non-negative integer. If the user enters a negative integer, the function prints a "sorry" statement and prompts the user again. It keeps on prompting until the user enters a non-negative number. The input function...
Find the least common multiple of these two expressions. 6x5v3u2 and 9v8u4    This is the...
Find the least common multiple of these two expressions. 6x5v3u2 and 9v8u4    This is the way the question is posted. I did more research. I believe the answer is 18x5v8u4
The greatest common divisor c, of a and b, denoted as c = gcd(a, b), is...
The greatest common divisor c, of a and b, denoted as c = gcd(a, b), is the largest number that divides both a and b. One way to write c is as a linear combination of a and b. Then c is the smallest natural number such that c = ax+by for x, y ∈ N. We say that a and b are relatively prime iff gcd(a, b) = 1. Prove that a and n are relatively prime if and...
Prove that any two nonzero elements of a UFD have a least common multiple, and describe...
Prove that any two nonzero elements of a UFD have a least common multiple, and describe the least common multiple in terms of the prime factorizations of the two elements.
Find the greatest common divisor of the given polynomials over the given field. Then write the...
Find the greatest common divisor of the given polynomials over the given field. Then write the greatest common divisor as a linear combination of the given polynomials. That is, given f(x) and g(x), find a(x) and b(x) so that d(x) = a(x)f(x) + b(x)g(x), where d(x) is the greatest common divisor of f(x) and g(x). (a) x^10 − x^7 − x^5 + x^3 + x^2 − 1 and x^8 − x^5 − x^3 + 1 over Q. (b) x^5 +...
. Let m be a positive integer, find the greatest common divisor of m and m+2
. Let m be a positive integer, find the greatest common divisor of m and m+2
Let m be a positive integer, find the greatest common divisor of m and m +...
Let m be a positive integer, find the greatest common divisor of m and m + 2. *Please go step by step*
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT