Can you please do this using c++? Q3 Russian peasant multiplication Russian peasant multiplication is an
Fantastic news! We've Found the answer you've been seeking!
Question:
Can you please do this using c++?
Transcribed Image Text:
Q3 Russian peasant multiplication • Russian peasant multiplication is an algorithm to multiply two (positive) integers. It is actually an old algorithm. There is evidence it was known by the ancient Egyptians. . It is simplest to explain with an example. Suppose we wish to multiply 89 x 21. 1. Let a 89 and b= 21. Form a table of three columns of numbers as follows. a 89 44 22 5 2 1 b 21 42 84 168 336 672 1344 21 168 336 1344 1869 (sum) 2. At each step, if a is odd, we copy the value of b into the third column. 3. Then we divide a by 2 (integer division) and multiply b by 2. 4. We stop when the value of a reaches 0. 5. The value of a x b is the sum of the numbers in the third column. Hence the algorithm breaks down the multiplication of two (possibly large) numbers into a set of additions and integer multiplications and divisions by 2. 1. Integer multiplication and division by 2 are easy operations in binary. 2. Integer multiplication by 2 is a left shift of the binary digits of a number. 3. Integer division by 2 is a right shift of the binary digits of a number (and loss of the "least significant bit"). 4. Addition is also a simpler operation than multiplication, in general. • Implement a function for Russian peasant multiplication of two positive integers. int RPM(int a, int b); 1. Declare and initialize a temporary variable int sum 0. 2. Begin a loop. (a) If a is odd then increment sum = sum + b. (b) Perform integer division a = a/2 and integer multiplication b = b*2. (c) Repeat the loop. Stop when a = 0). 3. Return the value of sum. Set a and b to the first and last four digits of your student id. If id 23054611, then a=2305 and b= 1611. Use your function to multiply a x b.. Q3 Russian peasant multiplication • Russian peasant multiplication is an algorithm to multiply two (positive) integers. It is actually an old algorithm. There is evidence it was known by the ancient Egyptians. . It is simplest to explain with an example. Suppose we wish to multiply 89 x 21. 1. Let a 89 and b= 21. Form a table of three columns of numbers as follows. a 89 44 22 5 2 1 b 21 42 84 168 336 672 1344 21 168 336 1344 1869 (sum) 2. At each step, if a is odd, we copy the value of b into the third column. 3. Then we divide a by 2 (integer division) and multiply b by 2. 4. We stop when the value of a reaches 0. 5. The value of a x b is the sum of the numbers in the third column. Hence the algorithm breaks down the multiplication of two (possibly large) numbers into a set of additions and integer multiplications and divisions by 2. 1. Integer multiplication and division by 2 are easy operations in binary. 2. Integer multiplication by 2 is a left shift of the binary digits of a number. 3. Integer division by 2 is a right shift of the binary digits of a number (and loss of the "least significant bit"). 4. Addition is also a simpler operation than multiplication, in general. • Implement a function for Russian peasant multiplication of two positive integers. int RPM(int a, int b); 1. Declare and initialize a temporary variable int sum 0. 2. Begin a loop. (a) If a is odd then increment sum = sum + b. (b) Perform integer division a = a/2 and integer multiplication b = b*2. (c) Repeat the loop. Stop when a = 0). 3. Return the value of sum. Set a and b to the first and last four digits of your student id. If id 23054611, then a=2305 and b= 1611. Use your function to multiply a x b..
Expert Answer:
Answer rating: 100% (QA)
C code with output for a89b21 maincpp 1 include 2 using namesp... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Can you please do the question above the name ishita in like 6-7 pages. 1. Jaskaran: What is consumer surplus? What is Producer surplus? Graph, Example and Mathematical explanation for each. 2....
-
Please speculate: Why do you think this UK Hoover fiasco happened in the first place? What went wrong?
-
Please explain and show me how to do this on Access. Thank you! I posted this question before, and the person who answered did not answer the full question and did not answer it correctly, I have...
-
1 Which branch of our government makes our laws? A O All choices Judicial Legislative Executive
-
List the errors you find in the following balance sheet. Prepare a corrected balancesheet. Eucalyptus Services Co. Balance Sheet For the Year Ended July 31, 2008 Assets Liabilities Current assets:...
-
Identify organs in the human body that are normally colonized by microorganisms. Which organs are normally devoid of microorganisms? What do the organs in each set have in common?
-
Determine which of -38 and 27 is larger using a number line, and express that using both the greater than and the less than notations.
-
Danner Company expects to have a cash balance of $45,000 on January 1, 2014. Relevant monthly budget data for the first 2 months of 2014 are as follows. Collections from customers: January $85,000,...
-
TIF PROBLEM SIXTEEN - 8 ACB Of Consideration And PUC Janice Tabor has a depreciable property that she wishes to transfer to a new corporation under the provisions of Section 85(1). The property has a...
-
The Sally Coffee Shop is considering closing one hour earlier in the evening through the week. Sally obtained the following data from a study taken last week of the number of customers between the...
-
A particular insurer has a solvency ratio of 0.85. The insurer experienced 405,000 in net profits and 30,000 in depreciation in the last year. If the insurer has 500,750 in long-term liabilities,...
-
Explain why complexity economics focuses on non-equilibrium analysis rather than equilibrium analysis.
-
Suppose government spending increases. Would the effect on AD be larger if the central bank took no action in response, or if the central bank were committed to maintaining a fixed interest rate?...
-
Why is there concern over the loss of biodiversity?
-
How can the study of contemporary foragers provide us with an understanding of Paleolithic lifestyles?
-
Explain why feminist economists criticize the use of GDP as a measure of well-being.
-
Find one family system and then discuss two to three cultural considerations when counseling from a psychoanalytic family perspective.Include at least one scholarly source to support your response....
-
Would you use the adjacency matrix structure or the adjacency list structure in each of the following cases? Justify your choice. a. The graph has 10,000 vertices and 20,000 edges, and it is...
-
Calculate the amount of the child and dependent care credit allowed for 2012 in each of the following cases, assuming the taxpayers had no income other than the stated amounts. a. William and Carla...
-
Rebecca and Walter Bunge have been married for 5 years. They live at 883 Scrub Brush Street, Apt. 52B, Las Vegas, NV 89125. Rebecca is a homemaker and Walt is a high school teacher. Rebecca's Social...
-
Phil and Linda are 25-year-old newlyweds and file a joint tax return. Linda is covered by a retirement plan at work, but Phil is not. a. Assuming Phil's wages were $27,000 and Linda's wages were...
-
You are valuing the equity in a firm with \($800\) million (face value) in debt with an average duration of six years and assets with an estimated value of \($400\) million. The standard deviation in...
-
Marion Manufacturing, a steel company, announces that it will be taking a major restructuring charge that will lower earnings this year by $500 million. Assume that the charge is not tax deductible...
-
General Systems is a firm that manufactures personal computers. As a top manager in the firm, you are considering changes in the way the firm is run. Currently, the firm has after-tax operating...
Study smarter with the SolutionInn App