Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This assignment is to write a program that asks the user for a positive integer (greater than zero). Verify that you have received a valid

This assignment is to write a program that asks the user for a positive integer (greater than zero). Verify that you have received a valid number and trap the user if they have not given a valid input value. Ask the user for another positive integer and verify this one also. Notice that the operation of getting a positive integer is the same in both cases. Use a single function, e.g. getInt(), for this task that returns the positive integer that the user types in. Then you can simply call the function twice to get the values that you need.

Once you have two positive integers, use a function, which you must call getGCD. Your function will take 2 positive integers as arguments and return the largest integer that evenly divides both of the input values (the GCD). The function should compute this value using Euclid's method; gcd(a, 0) = a and if b > a then gcd(a, b) = gcd(b mod a, a). More information on the strategy is available on the linked article. Your function will return the GCD to the main function. Print the result from the main function (not within the getGCD function). Notice that you will need to write at least 2 functions, one to get a valid user input and one to calculate. Your program output should look like the following:

image text in transcribed

Please enter a positive integer: -1 I'm sorry, that number is unrecognized or not positive. Please enter a positive integer: 0 I'm sorry, that number is unrecognized or not positive. Please enter a positive integer: stop I'm sorry, that number is unrecognized or not positive. Please enter a positive integer: 20 Please enter a second positive integer: 8 The largest integer that divides both 20 and 8 is: 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions