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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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