Determines the greatest common divisor of two numbers

Assignment Help Computer Engineering
Reference no: EM131864487

Assignment

Task 1

Write and test a iterative function that determines the greatest common divisor (GCD) of two numbers.

Requirements

• Name your function gcd. Your function must take two parameters. You may assume that the inputs provided to your function are integer values. That is, you do not need to do any error-checking to confirm that they are integer values.

• Write a test function called test gcd that tests your gcd function by calling it several times with different inputs. You should have at least six (and perhaps more) tests. Choose inputs that test different aspects of your function. For example, you may have one test gcd(5,5), that checks that the function works properly when the inputs are both positive and the same value. Once you have this test, you do not need another test gcd(8,8), as this checks the same thing. You should not use any tests involving inputs that are not integers.

Task 2

Write and test a iterative function that determines the least common multiple, lcm, Of two numbers.

Requirements

• Name your function lcm. Your function must take two parameters. You may assume that the inputs provided to your function are integer values. That is, you do not need to do any error-checking to confirm that they are integer values.

• Write a test function called test lcm that tests your lcm function by calling it several times with different inputs. You should have at least six (and perhaps more) tests. You should not use any tests involving inputs that are not integers.

Task 3

Write and test a iterative function that determines a number raised to a power, pow.

Requirements

• Name your function pow. Your function must take two parameters; a number and the power it is to be raised to. You may assume that the inputs provided to your function are integer values. That is, you do not need to do any error-checking to confirm that they are integer values.

• Write a test function called test pow that tests your pow function by calling it several times with different inputs. You should have at least six (and perhaps more) tests. You should not use any tests involving inputs that are not integers.

Task 4

Write and test a iterative function that determines if the first number is a factor of the second number, is factor. It will return a True or False answer.

Requirements

• Name your function is factor . Your function must take two parameters; a number and the number to see if it is a factor of. You may assume that the inputs provided to your function are integer values. That is, you do not need to do any error-checking to confirm that they are integer values.

• You must user iteration. The usage of modulo it prohibited in this function.

• Write a test function called test is factor that tests your is factor function by calling it several times with different inputs. You should have at least six (and perhaps more) tests. You should not use any tests involving inputs that are not integers.

Task 5

Write a main function to allow a user to select and run one of the functions above.

The function should display the available functions to the user and allow then to input one to select. Then based on the function selected it should prompt the user for the required function inputs.

Example Operation:
List of functions

1. POW
2. GCD
3. LCM
4. is_factor

Please select a function: 1

Please enter the base: 2 Please enter the exponent: 3

The 2 raised to the 3 power is 8

6 Programming Tips

Modulo

Python provides an operator that computes the remainder when one number is divided by another. It is very useful - we will see it again in this course! It is called the modulo operator. From the interactive console:

>>> 8 3
2
>>> 4 11
4
>>> 60 5
0

Simple print Formatting

Normally, if you execute a print statement like

print( 5, "x", 2 ) your output looks like 5 x 2

If you want there to be no spaces between the values printed, add a value for a special, named parameter sep:

print( 5, "x", 2, sep="" )

Reference no: EM131864487

Questions Cloud

Write nested decision structures that perform given problem : Write nested decision structures that perform the following: If amount1 is greater than 10 and amount2 is less than 100, display the greater of amount1 and amou
Why leaders should understand the nature of personality : Why the leaders should understand the nature, role and dimensions of personality? Which dimensions are important to you as a leader and why?
Decided to sell new line of golf clubs : McGilla Golf has decided to sell a new line of golf clubs. The clubs will sell for $840 per set and have a variable cost of $440 per set.
Pertaining to a criminology class : This is a discussion assignment. Can you discuss your thoughts on this, while pertaining to a criminology class.
Determines the greatest common divisor of two numbers : Write and test a iterative function that determines the greatest common divisor (GCD) of two numbers.
Create different bloodstain patterns : Create different bloodstain patterns and analyze the patterns using these instructions and the following materials:
Implement the incident command system : Major portions of the city have been affected by sudden severe weather with hail and heavy rains. These have caused the North River to flood parts
What is the companys financial health : What is the company's financial health (new products, expansion efforts, company risks, whether revenues are growing or stable, etc.)?
What is the optimum number of times per quarter : What is the optimum number of times per quarter that Domino should sell the bills?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Company pays in sales person on the commission basis

make a C++ program that uses a "While" statement to input each salesperson's gross sale for last week and calculates and displays that salesperson's earnings. Process one salesperson's figure at a time.

  What usually causes "illegal start of expression" errors

Does anyone have any ideas what usually causes "illegal start of expression" errors? Is there something the compiler is looking for in general? I am trying to debug a program and I keep getting this error. This error is before one of my public voi..

  Alternative design strategies for a system

A secondary purpose is to emphasize to you that the consideration of a packaged software solution should be done after the analysis efforts are complete, not as a substitute for analysis. Let us now begin. What processes are needed in order to sha..

  Efficiency and effectiveness of project communications

An effective communication strategy is absolutely essential for achieving effective project integration management. Any time the aim is to integrate numerous concurrently operating activities, the role of communication becomes central. This is as ..

  What are the major problems of nrz

What are the major problems of NRZ (Non-Return to Zero) encoding/signaling? Is there any case where it's use could be acceptable? explain.

  Draw simple sketch that show each virtual channel connection

One disadvantage of ATM is the 5-byte cell tax. Explain what this means. Draw a simple sketch that shows each virtual channel connection.

  What is the annual yield anticipate for the investment

Assume that the client's risk index could be increased to 0.06. How much would the yield increase, and how would the investment recommendation change.

  Resolving the ambiguities in the software

Describe what you must do in such a situation. You know that cost to your current employer will increase in case the ambiguities are not resolved. Though, you have also a responsibility of confidentiality to your previous employer.

  Write section of assembly language code for microcontrollers

Write a section of assembly language code for your microcontrollers to implement the given design, where K I and K2 are 8-bit unsigned numbers in memo,).

  Prepare a scale plot of heat flux

The heat flux along a cooling tube in a typical nuclear power reactor may often be approximated.

  Problem related to the skylights

Skylights or "roof windows" are commonly used in homes and manufacturing facilities since they let natural light in during day time.

  Why is information security a management problem

Why is information security a management problem? What can management do that technology cannot? Why is data the most important asset an organization possesses? What other assets in the organization require protection?

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