Write a program that takes two non-negative integers

Assignment Help Computer Engineering
Reference no: EM132211450

Write a program that takes two non-negative integers from standard input and calculates their greatest common divisor (gcd).

Recall that the greatest common divisor of two integers is the largest positive integer that is a divisor of both numbers.

For example, the gcd of 6 and 9 is 3; the gcd of 16 and 32 is 16; and. by number theory, the gcd of 0 and a, for a = 0, 1, 2, ... is a. At the start of the program, prompt the user to input two integers by printing "Calculate GCD (A, B).

Input A B:\n". If either input is negative, then print "Both inputs must be non-negative.\n". If both inputs are non-negative, then print their gcd as "The gcd is .\n", where is replaced by your calculated gcd.

As part of your program, you must make a function that takes two integer arguments and returns their gcd as an integer.

You can use the following function prototype: int gcd(int a, int b); Example input/output pairs (excluding the prompt) are provided below: Input: 6 9; Output: The gcd is 3. Input: 32 16; Output: The gcd is 16. Input: 4 0; Output: The gcd is 4. Input: -1 3; Output: Both inputs must be non-negative.

Reference no: EM132211450

Questions Cloud

Write a program that solves the coin row problem : Write a program that solves the Coin Row problem in the C++ language. Your program should ask a user for the number of coins and coin values.
Write a program that reads ten numbers from the screen : Write a program that reads 10 numbers from the screen, calculates the mean (average), finds the minimum and maximum values, and outputs them to the screen.
Create a list of these numbers and find the arithmetic mean : Write a program for: In a text file INPUT integers separated by a space, perhaps in a few lines.
Write a program that reads a file of dna data : Write a program that reads a file of DNA data and searches for protein sequences. DNA data consists of long strings of the letters A,C,G, and T.
Write a program that takes two non-negative integers : Write a program that takes two non-negative integers from standard input and calculates their greatest common divisor (gcd).
Write a program that reads its input into an array : Write a program that reads its input into an array and then uses selection sort to sort the array. In selection sort, we first find the smallest element.
Write a program that can be used by a small theater : Write a program that can be used by a small theater to sell tickets for performances.
Calculate team a record at the end of the season : Write a program that reads file called bballscores.txt containing the score of Team A's basketball games. The file will contain two numbers per line.
Create an array that will store input data for daily sales : Write a program using an array that will process sales data for a week. Create an array that will store input data for the daily sales for a week (7 days).

Reviews

Write a Review

Computer Engineering Questions & Answers

  Questionusing matlabdescribes a function named insidecircle

questionusing matlabdescribes a function named insidecircle that takes 3 arguments as input- the center of the circle

  What is the two-block message that you chose

Explain how to forge the MAC for a two-block message of your choice. What is the two-block message that you chose?

  The open systems interconnection model is inherently

the open systems interconnection model is inherently inefficient. on the source host each layer must take the work of

  What are the advantages of thunderbolt

What are the advantages of Thunderbolt? When might one use SCSI to interconnect a peripheral? What is the difference between SCSI and iSCSI?

  Write a program that accept 20 numbers from the user

Write a program that accept 20 numbers from the user (numbers can range from -100 to 100) and outputs the sorted numbers in ascending order.

  Write a function to merge two linked lists

Write a function to merge two linked lists. The input lists have their elements in sorted order, from lowest to highest.

  A program stopped running when its name was changed

A program stopped running when its name was changed. Why? What is the exit status of a command, and where is it stored?

  Suggestions for ensuring an adequate change control

What are two suggestions for ensuring the adequate change control on projects that involve outside contracts.

  What is probability that it contains exactly k white balls

An urn contains m white and n black balls. If a random sample of size r is chosen, what is the probability that it contains exactly k white balls?

  Create a set of three priority interrupts

Create a set of three priority interrupts and show how they are executed between times 0 and 80 ns. Only one program or interrupt can run at a time.

  Why database re-engineering and redesign is required

define what should be done when adding tables and relationships for normalization.

  Write a function that takes a rectified waveform

Write a function that takes a rectified waveform and returns a waveform that approximates an RC filter output.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd