Write a function - greatest common divisor

Assignment Help C/C++ Programming
Reference no: EM13872209

Write a function named "g_c_d" that takes two positive integer arguments and returns as its value the greatest common divisor of those two integers.

If the function is passed an argument that is not positive (i.e., greater than zero), then the function should return the value 0 as a sentinel value to indicate that an error occurred.

Thus, for example, cout << g_c_d(40,50) << endl; // will print 10 cout << g_c_d(256,625) << endl; // will print 1 cout << g_c_d(42,6) << endl; // will print 6 cout << g_c_d(0,32) << endl; // will print 0 (even though 32 is the g.c.d.) cout << g_c_d(10,-6) << endl; // will print 0 (even though 2 is the g.c.d.)

Reference no: EM13872209

Questions Cloud

Prepare the journal entries to record acquisition of mining : Prepare the journal entries to record the acquisition of the mining equipment and the asset retirement obligation for the mine on January 1, 2014.
How the sequential and additive composition adaptors differ : how the sequential and additive composition adaptors differ
Demonstration before the noblemen : In 1654 Otto von Guericke, inventor of the air pump gave a demonstration before the noblemen of the Holy Roman Empire in which two teams of eight horses could not pull apart two evacuated brass hemispheres.
Fluid property having dimensions : If V is a velocity, l a length and v a fluid property having dimensions of L2T-1, which of the following combinations are dimensionless:
Write a function - greatest common divisor : Write a function named "g_c_d" that takes two positive integer arguments and returns as its value the greatest common divisor of those two integers.
Molecules of the first be heavier : If one material has a higher density than another, must the molecules of the first be heavier those of the second? Explain
What is the trignomerty leveling : What is the trignomerty leveling? Explain in detail.
Drag force on the bubble is negligible : If a bubble in sparkling water accelerates upward at the rate of 0.225 m/s2 and has a radius of 0.500 mm, what is its mass? Assume that the drag force on the bubble is negligible.
Trend reports on the topic information technology : Write five trend reports on the topic Information Technology & business starting with January-December 2015 (nothing earlier) in hard (paper) and soft (electronic file)

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Microsoft project file work breakdown structure

Update the Microsoft Project file you created in (Work Breakdown Structure) with the following changes.

  Write a program that allows a salesclerk to enter an item

Write a program in C++ that allows a salesclerk to enter an item's price and the quantity purchased by a customer.

  Prepare a linux shell

Prepare a linux shell (in other words, write a C/C++ program) that will recursively prompt for input from the user. The shell should prompt as

  Build a definition for a class that stores data

Using C++ language, build a definition for a class that stores data about a two dimensional vector. The class has to have mutators and accessors to get and set the x and y values. Make x and y integers. Then overload the operator * so that it retu..

  Write an lc-3 machine language program

Write an LC-3 machine language program starting at location x3000 which divides the number in memory location x4000 by the number in memory location x4001 and stores the quotient at x5000 and the remainder at x5001.

  Change temperature fahrenheit to celsius and kelvin

Write a program in c++ that takes the temperature in Fahrenheit and convert it to Celsius And Kelvin:

  Prepare the weighted scoring model for three exams

Prepare the weighted scoring model. Final grades are based on three exams worth 15%, 20%, and 25%, respectively; homework is worth 20%.

  Print each employee''s identification number

1) in a program you need to store the identification numbers of 10 employees (as ints) and their weekly gross pay (as doubles) A) Define two arrays that may be used in parallel to store the 10 employee indentificcation numbers and gross pay amounts B..

  Cancer genome identification tool

Cancer Genome Identification Tool - Create structure charts for a given problem - Determine an appropriate functional decomposition or top-down design from a structure chart

  Write a loop to total and average the contents of the array

Given the following code, write a loop to total and average the contents of the array.

  Quiz on c coding

Which of the following statements is incorrect

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