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

  Techniques for information hiding and encapsulation

What techniques did you utilize for information hiding and encapsulation? Are there any improvements you would make? If so, what would they be?

  Prepare a linux shell in other words write a cc program

prepare a linux shell in other words write a cc program that will recursively prompt for input from the user. the shell

  Create the need matrix

Creating a system having five process from p0 to p4 and five resource types.

  Write a program that allows user to input students names

Write a program that allows the user to input the students' names followed by their test scores and outputs the following.

  Define a class named payment that contains an instance

Define a class named Payment that contains an instance variable of type double that stores the amount of the payment and appropriate accessor and mutator methods.

  Questions related to c programming

Which statement will read a floating point value from the keyboard and store it in the variable x? A. printf("float = %f", x); B. scanf("%f", &x); C. scanf("&f", %x); D. scanf("%d", &x);

  Write a function to compute the volume of a cone

write a function to compute the volume of a cone by using the base radius r and the height h of the cone as the parameters of the function Vcone = xr^2h/3

  Program to play lottery

The program randomly generates a Lottery of a three-digit number ( any number from 100 to 999), prompts the user to enter a three-digit number, and determines whether the user wins according to the subsequent rule:

  A perfect solution is impossible or too expensive

Optimization is often encountered in engineering problems. More often than not, a perfect solution is impossible or too expensive to find and implement. Therefore, we resort to sub-optimal, yet useful, solutions. This assignment tackles a classical p..

  Design a class called complex

Design a class called Complex. The class enables operations on so called complex numbers. These are numbers of the form realPart + imaginaryPart *i, where the i has the value

  Program for search the telephone number

To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN.

  Function that returns a token when it is needed.

A major component of your assignment will be to write a procedure (Function) that returns a token when it is needed. Your lexer should return a record, one field for the token and another field the actual "value" of the token (lexeme), i.e. the in..

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