Question

Write a C program for the following requirement, t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

int main(void)
{
int n1, n2, n3, i, gcdtwo,gcdthree;

printf("Enter three composite numbers: ");
scanf("%d %d %d", &n1, &n2, &n3);

for(i=1; i <= n1 && i <= n2; ++i)
{
// Checks if i is factor of both n1 and n2
if(n1%i==0 && n2%i==0)
gcdtwo = i;
}
for(i=1; i <= gcdtwo && i <= n3; ++i)
{
// Checks if i is factor of both gcdtwo, the gcd of two numbers and n3
if(gcdtwo%i==0 && n3%i==0)
gcdthree = i;
}

printf("G.C.D of %d ,%d and %d is %d", n1,n2,n3, gcdthree);
   return 0;
}

output:

Enter three integers: G.C.D of 15 , 65 and 45 is 5
Add a comment
Know the answer?
Add Answer to:
Write a C program for the following requirement, thank you! Write a program that takes three...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete C++ program to ask the user to inter two integers and the program...

    Write a complete C++ program to ask the user to inter two integers and the program finds and display the greatest common divisor (GCD) of the two integers. Typical output screen should be as following: Write a complete C++ program to ask the user to inter two integers and the program finds and display the greatest common divisor (GCD) of the two integers. Typical output screen should be as following: Enter two integers 18 27 The GCD is = 9

  • Write a complete C++ program to ask the user to inter two integers and the program...

    Write a complete C++ program to ask the user to inter two integers and the program finds and display the greatest common divisor (GCD) of the two integers. Typical output screen should be as following: Enter two integers 18 27 The GCD is = 9

  • Write a C++ program that reads in two integers and then computes the greatest common divisor...

    Write a C++ program that reads in two integers and then computes the greatest common divisor GCD using recursion. DO NOT USE A BUILT-IN FUNCTION SUCH AS "gcd" to do this.

  • Using SPIM, write and test a program that finds the Greatest Common Divisor of two integers...

    Using SPIM, write and test a program that finds the Greatest Common Divisor of two integers using a recursive function that implements Euclid's GCD algorithm as described below. Your program should greet the user "Euclid's GCD algorithm", prompt the user to input two integers, and then output the result "Euclid's Greatest Common Divisor Algorithm" GCD(M,N) = M                      (if N is 0) GCD(M,N) = GCD(N, M % N)   (if N > 0) you may assume that inputs are non-negative name your assembly...

  • PYTHON In mathematics, the Greatest Common Divisor (GCD) of two integers is the largest positive integer...

    PYTHON In mathematics, the Greatest Common Divisor (GCD) of two integers is the largest positive integer that divides the two numbers without a remainder. For example, the GCD of 8 and 12 is 4. Steps to calculate the GCD of two positive integers a,b using the Binary method is given below: Input: a, b integers If a<=0 or b<=0, then Return 0 Else, d = 0 while a and b are both even do a = a/2 b = b/2...

  • Extended Euclidian Algorithm (page 4 of last lecture, more on algorithms) Write code that asks for...

    Extended Euclidian Algorithm (page 4 of last lecture, more on algorithms) Write code that asks for and gets two integers, then computes and displays their greatest common divisor using the Extended Euclidian Algorithm (EEA). The EEA should be implemented as a function that takes two integers are arguments and prints their GCD.

  • C++ PROGRAM ONLY! For this lab you need to write a program that will read in...

    C++ PROGRAM ONLY! For this lab you need to write a program that will read in two values from a user and output the greatest common divisor (using a recursive implementation of the Euclidean algorithm) to a file. In Lab #3, you implemented this program using an iterative method. Greatest Common Divisor In mathematics, the greatest common divisor (GCD) of two or more integers (when at least one of of them is zero then the larger value is the GCD....

  • 1. (10 points) GCD Algorithm The greatest common divisor of two integers a and b where...

    1. (10 points) GCD Algorithm The greatest common divisor of two integers a and b where a 2 b is equal to the greatest common divisor of b and (a mod b). Write a program that implements this algorithm to find the GCD of two integers. Assume that both integers are positive. Follow this algorithm: 1. Call the two integers large and small. 2. If small is equal to 0: stop: large is the GCD. 3. Else, divide large by...

  • For number 25, can someone explain to me how they got (2^(ab-b)+2^(ab-2b)+2^(ab-3b)+...+(2^(ab-ab)) and how they reache...

    For number 25, can someone explain to me how they got (2^(ab-b)+2^(ab-2b)+2^(ab-3b)+...+(2^(ab-ab)) and how they reached to that conclusion? For number 29, can someone explain to me how "it can't be greater than the greatest common divisor of a-b and b"? I would think that gcd(a, b) would be greater than gcd(a-b, b) because "a" and "b" are bigger than "a-b" and "b" so that confused me. Thank you! 25. Ifn e N and 2n - 1 is prime, then...

  • write code using void function i need the code in C++ but make sire u solve...

    write code using void function i need the code in C++ but make sire u solve by using void function visor (GCD) of two integers is the largest nacd that returns the greatest com- its digits reversed. For example, 5.31 (Greatest Common Divisor) The greatest common divisor (GCD) of two in integer that evenly divides each of the numbers. Write a function gcd that returns the mon divisor of two integers. . . for Numeric Grades) Write a function qualityPoints...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT