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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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