Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING PYTHON USING PYTHON Problem 1 (Text book, problem 4, programming projects, chapter 2, page 158) Weird multiplication For this assignment, you will be implementing

USING PYTHON

image text in transcribed

USING PYTHON

Problem 1 (Text book, problem 4, programming projects, chapter 2, page 158) Weird multiplication For this assignment, you will be implementing the so-called "Russian Peasant" or "Ancient Egyptian method for multiplication. It looks a little odd, but just think of it as an algorithm, a recipe for doing multiplication in a way other than what you learned in grade school. The algorithm is as follows. If A and B are the 2 integers (only integers) to be multiplied, we repeatedly multiply A by 2 and divide B by 2, until B cannot be divided any further, that is, until its value becomes 0 (remember, this is integer division). During each step, whenever B is an odd number, we add the corresponding A value to the product we are generating. In the end, the sum of the A values that had corresponding odd B values is the product. Get it? Here is an example If the two integers to be multiplied are 34 and 19, the operations would be: Comment 34 68 136 272 544 19 Add A to the product, B is odd 9 Add A to the product, B is odd 4 Ignore this A value, B is even 2 Ignore this A value, B is evern 1 Add A to the product, B is odd Sum up all the A values that had odd B values and you get: 34+68+544- 646>Final product. (a) Part 1: Write a program to find the product of two integers (b) Part 2: Modify your program so that it repeatedly asks whether you want to find another product

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

What is Indian Polity and Governance ?

Answered: 1 week ago