hello
can someone help me write an program for this. I am really confused on where to even start. I would really if someone can help me with it,
I will be implementing an algorithm for Russian Peasant multiplication. Your program will ask the user for two
integers (positive or negative), and show the progress of the algorithm as it computes the result.
The algorithm works as follows. Suppose we have 2 integers A and B. We repeatedly double A, while
dividing B by 2 using integer division (dropping fractions). At each step, if B is odd, we add the
current value of A to the answer, continuing until B is 0.
An example may make this clearer:
Multiplying 56 and 37. Answer so far = 0.
A = 56, B = 37 B is odd, so add 56 to answer.
A = 112, B = 18 B is even, ignore A for now.
A = 224, B = 9 B is odd, add current value of A (224) to answer.
A = 448, B = 4 B is even, ignore A for now.
A = 896, B = 2 B is even, ignore A for now.
A = 1792, B = 1 B is odd, add current value of A (1792) to answer.
A = 3584, B = 0 B is 0 STOP.
Answer = 56 + 224 + 1792 = 2072.
Specification:
Your program should inform the user the values of A and B at each step of the algorithm, and
when A is being added to the total.
Your program must use at least one selection (if/else, may or may not have an elif) and at least
one repetition (loop, such as while) statement.
someone please help me. This is my first programming class and everything and i am just getting lost with everything.
/>
can someone help me write an program for this. I am really confused on where to even start. I would really if someone can help me with it,
I will be implementing an algorithm for Russian Peasant multiplication. Your program will ask the user for two
integers (positive or negative), and show the progress of the algorithm as it computes the result.
The algorithm works as follows. Suppose we have 2 integers A and B. We repeatedly double A, while
dividing B by 2 using integer division (dropping fractions). At each step, if B is odd, we add the
current value of A to the answer, continuing until B is 0.
An example may make this clearer:
Multiplying 56 and 37. Answer so far = 0.
A = 56, B = 37 B is odd, so add 56 to answer.
A = 112, B = 18 B is even, ignore A for now.
A = 224, B = 9 B is odd, add current value of A (224) to answer.
A = 448, B = 4 B is even, ignore A for now.
A = 896, B = 2 B is even, ignore A for now.
A = 1792, B = 1 B is odd, add current value of A (1792) to answer.
A = 3584, B = 0 B is 0 STOP.
Answer = 56 + 224 + 1792 = 2072.
Specification:
Your program should inform the user the values of A and B at each step of the algorithm, and
when A is being added to the total.
Your program must use at least one selection (if/else, may or may not have an elif) and at least
one repetition (loop, such as while) statement.
someone please help me. This is my first programming class and everything and i am just getting lost with everything.
