C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 6, Problem 6.31E
Program Plan Intro
- In the program, we include the header files as required.
- Function prototype will be declared.
- Declaring main() function as integer type.
- Taking the function gcd() as int type function to find the greatest common divisor number between two numbers.
- Variable declaration: gcd1 and gcd2 is aninteger type variable which will carry the user entered number from the main function to the gcd().
- Declaring the return_gcdas ainteger type which help to find the gcd number.
- num_1and num_2 are declared as integer type variables which takes input from the user in main() function.
- Calling the gcd() in the main().
- gcd() returns the greatest common divisor.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(Recursive Greatest Common Divisor) The greatest common divisor of integers x and y isthe largest integer that evenly divides both x and y. Write a recursive function gcd that returns thegreatest common divisor of x and y. The gcd of x and y is defined recursively as follows: If y is equalto 0, then gcd(x, y) is x; otherwise gcd(x, y) is gcd(y, x % y), where % is the remainder operator.
(Perfect Numbers) An integer is said to be a perfect number if the sum of its divisors, including 1 (but not the number itself), is equal to the number. For example, 6 is a perfect number, because 6=1+2+3. Write a functionisPerfect that determines whether parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. Print the divisors of each perfect number to confirm that the number is indeed perfect. Challenge the power of your computer by testing numbers much larger than 1000.
4. (Prime Numbers) An integer is said to be prime if it is divisible by only 1 and itself. For example, 2, 3, 5 and 7
are prime, but 4, 6, 8 and 9 are not.
Write a function called isPrime that receives an integer and determines whether the integer is prime or not.
Write a test program that uses isPrime to determine and prints all the prime numbers between 1 and 1000.
Display 10 numbers per line.
Chapter 6 Solutions
C++ How to Program (10th Edition)
Ch. 6 - Show the value of x after each of the following...Ch. 6 - (Parking Charges) A parking garage charges a...Ch. 6 - Prob. 6.13ECh. 6 - (Rounding Numbers) Function floor can be used to...Ch. 6 - Prob. 6.15ECh. 6 - (Random Numbers) Write statement that assign...Ch. 6 - (Random Numbers) Write a single statement that...Ch. 6 - Prob. 6.18ECh. 6 - Prob. 6.19ECh. 6 - Prob. 6.20E
Ch. 6 - Prob. 6.21ECh. 6 - Prob. 6.22ECh. 6 - Prob. 6.23ECh. 6 - (Separating Digits) Write program segments that...Ch. 6 - (Calculating Number of Seconds) Write a function...Ch. 6 - (Celsius and Fahrenheit Temperature) Implement the...Ch. 6 - (Find the Minimum) Write a program that inputs...Ch. 6 - Prob. 6.28ECh. 6 - (Prime Numbers) An integer is said to be prime if...Ch. 6 - Prob. 6.30ECh. 6 - Prob. 6.31ECh. 6 - (Quality Points for Numeric Grades) Write a...Ch. 6 - Prob. 6.33ECh. 6 - (Guess-the-Number Game) Write a program that plays...Ch. 6 - (Guess-the-Number Game Modification) Modify the...Ch. 6 - Prob. 6.36ECh. 6 - Prob. 6.37ECh. 6 - Prob. 6.38ECh. 6 - Prob. 6.39ECh. 6 - Prob. 6.40ECh. 6 - Prob. 6.41ECh. 6 - Prob. 6.42ECh. 6 - Prob. 6.43ECh. 6 - Prob. 6.44ECh. 6 - (Math Library Functions) Write a program that...Ch. 6 - (Find the Error) Find the error in each of the...Ch. 6 - (Craps Game Modification) Modify the craps program...Ch. 6 - (Circle Area) Write a C++ program that prompts the...Ch. 6 - (pass-by-Value vs. Pass-by-Reference) Write a...Ch. 6 - (Unary Scope Resolution Operator) What’s the...Ch. 6 - (Function Templateminimum) Write a program that...Ch. 6 - Prob. 6.52ECh. 6 - (Find the Error) Determine whether the following...Ch. 6 - (C++ Random Numbers: Modified Craps Game) Modify...Ch. 6 - (C++ Scoped enum) Create a scoped enum named...Ch. 6 - (Function Prototype and Definitions) Explain the...Ch. 6 - Prob. 6.57MADCh. 6 - Prob. 6.58MADCh. 6 - (Computer-Assisted Instruction: Monitoring Student...Ch. 6 - (Computer-Assisted Instruction: Difficulty Levels)...Ch. 6 - (Computer-Assisted Instruction: Varying the Types...
Knowledge Booster
Similar questions
- (GREATEST COMMON DIVISOR) The greatest common divisor of integers x and y is the largest integer that evenly divides into both x and y. Write and test a recursive function gcd that returns the greatest common divisor of x and y. The gcd of x and y is defined recursively as follows: If y is equal to 0, then gcd (x, y) is x; otherwise, gcd (x, y) is gcd (y, x % y), where % is the remainder operator.arrow_forward(Check test scores) The answers to a true-false test are as follows: T T F F T. Given a two-dimensional answer array, in which each row corresponds to the answers provided on one test, write a function that accepts the two-dimensional array and number of tests as parameters and returns a one-dimensional array containing the grades for each test. (Each question is worth 5 points so that the maximum possible grade is 25.) Test your function with the following data: int score = 0;arrow_forward-Functions Write a function int nth_Prime(int x) in C++ that takes a parameter x and returns nth prime number.arrow_forward
- (Square of Asterisks) Write a function that displays a solid square of asterisks whose side isspecified in integer parameter side. For example, if side is 4, the function displays: **** **** **** ****arrow_forward3- Write a function pow (double base, int exp) to calculate integral powers of floating-point numbers. Arguments: The base of type double and the exponent of type int. Returns: The power baseexp of type double. For example, calling pow( 2.5, 3) returns the value 2.53 = 2.5 * 2.5 * 2.5 = 15.625 This definition of the function pow( ) means overloading the standard function pow ( ), which is called with two double values. Test your function by reading one value each for the base and the exponent from the keyboard. Compare the result of your function with the result of the standard function. Hint: The power x° is defined as 1.0 for a given number x. • The power x" is defined as (1/x)-" for a negative exponent n. • The power 0" where n > 0 will always yield 0.0 not defined for n < 0. In this case, your function should return the The power 0n is value 0. Don't forget the negative exponentarrow_forwardQ2) (Perfect Numbers) An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3. Write a function perfect that determines if parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. Print the factors of each perfect number to confirm that the number is indeed perfect. Challenge the power of your computer by testing numbers much larger than 1000.arrow_forward
- integer) Write a function that computes the sum of the digits in an integer. Use the following function header:def sumDigits(n):For example, sumDigits(234) returns 9 (Hint: Use the % operator to extract digits, and the // operator to remove the extracted digit. For instance, toextract 4 from 234, use 234 % 10 To remove 4 from 234, use 234 // 10 (=23) Use a loop to repeatedly extract and remove the digits until all the digits are extracted.) Write a test program that prompts the user to enter an integer and displays the sum of all its digits.arrow_forward1. Square Flower You can have the turtle draw an interesting flower like sha pe by drawing n squares. Each n-square flower is drawn after turning the turtle by some number of degrees between each square. (see Figure 1 for an example) (a) Typel: A 5-square red flower. (b) A 15-square blue flower. Figure 1: Two types of n-square flowers Using the following implementation of draw square() function write a function na med draw flower() that takes a turtle, the number n of squares to draw, the side length and a color as parameters and draws an n-square flower by repeating the function draw square() n times. Test your code by drawing a yellow 21-square flower with side length of 200. def drav aqu ar e (aTurtle, sidelength): f or i in range (4) : aTurtle.forvard (side Length) aTurtle. 1eft (90)arrow_forwardProgramming Language : R programming (R Studio) A twin prime is a prime that has a prime gap of two. Sometimes the term twin prime isused for a pair of twin primes. For example, the five twin prime pairs are (3, 5), (5, 7),(11, 13), (17, 19) and (29, 31). Write a function that returns the number of all twin primepairs between 1 and a given number n.arrow_forward
- (Use python):The instructor of a lower division statistics class has assigned you a task: make a function that takes in a student’s score on a scale from 0 to 100 and assigns a letter grade based on the following grade boundaries.arrow_forward(Algebra: solve linear equations) Write a function that solves the following 2 x 2 system of linear equation: aoox + a01y = bo boa11 - bjao1 X = bja00 - boa10 a10x + any = bị y = agoa11 dooa11 - d01a10 The function header is const int SIZE = 2; bool linearEquation(const double a[][SIZE], const double b[], double result[]); The function returns false if apo1 - aoja10 is 0; otherwise, returns true. Write a test program that prompts the user to enter ao0. d01, a10, a11, bo, bị, and display the result. If aooa11 – a0ia10 is 0, report that "The equation has no solution". A sample run is similar to Programming Exercise 3.3.arrow_forward(2) The ceiling of a floating-point number x is the smallest integer that is still larger than or equal to x. Alternatively, the ceiling of a floating-point number x is what you get when you round x up to the nearest integer. For example, the ceiling of 2.1 is 3, the ceiling of 0.9 is 1, the ceiling of -4.5 is -4, etc. Write a function called ceiling (number) to compute the ceiling of a floating-point number (input argument) and returns one integer value. You may not use python's ceil() or floor() functions. Your function may use int() and/or float() functions, and your solution must use the floor division operator (i.e., '//").arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr