Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

These should be done by Python The GCD (greatest common divisor) and LCM (least common multiple) of two numbers that your codes from the user.

These should be done by Python image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
The GCD (greatest common divisor) and LCM (least common multiple) of two numbers that your codes from the user. GCD is the largest number that both are divisible by and LCM is the smallest number that is the multiple of two numbers. For instance, GCD (18,42) is 6 because the langest number that both 18 and 42 are divisible by is 6 . The LCM of 18 and 42 is 126. Write a program that asks the user for two numbers and computes their GCD. Shown below is a way to compute the GCD, called Euclid's Algorithm. - First compute the remainder of dividing the larger number by the smaller number - Next, replace the larger number with the smaller number and the smaller number with the remainder. - Repeat this process until the smaller number is 0 . The GCD is the last value of the larger number. In order to find the LCM of the two given numbers, start with the largest number and increase the numbers by one until you find a number, which is divisible by the both given numbers. NOTE: If the user enters twa float numbers, the code should issue an error message. For example, if a=5. and b=2., then the output from the program should be: Enter the first integer number: 5 Enter the second integer number: 2 The Greatest Common Divider is: 1 The Larger Comnon Multiplier is: 10 Programmed by Stew Dent. Date: Sun Jan 29 10:05:34 2023 End of processing. If a=6.4, and b=4, then the output from the program should be: Enter the first integer number: 6.4 Enter the second integer number: 4 A float value is entered which is not acceptablel Programed by Stew Dent. Date: Sun Jan 29 10:07:40 2023 End of processing. The purpose of this question is to calculate the three cubic roots of a complex number. A complex number is of the form a+ib where i is 1. The magnitude r of a complex number is a2+b2. The complex number a+ib can be written as r(cos+isin). Therefore a=rcos and b=rsin and b/a=(rsin)/(rcos)=tan. =arctan(b/a) The 3 cubic roots of a complex number are computed using the following expression: r31[cos(32k+)+isin(32k+)] There is one root for k=0, a second root for k=1 and a third root for k=2. In addition to finding the cubic roots of a complex number the program must calculate and display the value of the cube of each of the roots to verify that each root is correct. Use input to read in the values for a,b. The type of a and b must be float. The value entered for a must not be zero as that will cause a divide by zero error. When displaying the output be sure to use the correct format codes. See the next page for sample input to and output from the program. Your input and output should match the sample as closely as possible. If a=5. and b=2, then the output from the program should be: Enten the real part of the complex number: 5 . Enter the imaginary part of the complex number: 2 . The complex number is (5+2j) root1=(1.7387225818854102+0.22172191801348856j)root13=(5+2j)root2=(1,0613781045181963+1.3949169670396901j)root23=(5.000000000000001+1.999999999999995j)root3=(0.67734447736721431.616638885053178j)root3=(5.000600000000003+1.9999999999999933j) Programmed by Stew Dent. Date: Sun Jan 2911:16:122023 End of processing. If a=6.75, and b=4.37, then the output from the program should be: Enter the real part of the complex number: 6.75 Enter the imaginary part of the complex number: 4.37 The complex number is (6.75+4.37j) root1=(1.9667904755636736+0.3813473662151226j)root3=(6.750000000000001+4.37j)root2=(1.3136517445904201+1.5126168326518574j)root23=(6.7500000000000036+4.369999999999995j)root3=(0.65313873097325381.8939641988669795j)root3=(6.750000000000007+4.369999999999992j) Programined by Stew Dent. Date: Sun Jan 29 11:19:21 2023 End of processing. Test the program with the values given above and hand in the program. Write a piece of code in Python that grabs N in the input and print out the N number of the sequence below: (in this example, the user had entered 10 as the number of the desired terms) Finding the relationship between the terms is a part of the question mark. Hint: In order to find the relationship between the terms of the series, you need to find how each term is built using the pervious term and its index. For example: 5=1+412=5+4+322=12+4+3+335=22+4+3+3+351=35+4+3+3+3+3 Ask the user to enter the numerator and denominator of a fraction, and the position of the decimal digit they want to know. For Example, if the user enters a numerator of 1 and a denominator of 7 and wants to know the 4th digit after decimal point, your program should print out 8 , because 1/7=142856 and 8 is the 4th digit after decimal point. One way to do this is to mimic the long division process you may have learned in grade school. It can be done in about five lines using the // operator at one point in the program. Hint: In order to find the first digit of any number, it is only needed to find the reminder of that number by 10 . For example, 1275%10=5 which is the first digit of 1275 . Bonus Chance: If you write this code without any loop, you will get 5% bonus of the mark of this assignment. Please mention it in your solution that this is the bonus part. Below is the expected output of the code for some example: Enter the numerator: 93 Enter the denominator: 26 Enter the position of the decimal digit that you want: 3 The answer of the division is: 3.57692307692 6 is placed in position 3 after decimal point. Programmed by Stew Dent. Date: Sun Jan 2912:15:282023 End of processing

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 Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions