Starting from:
$30

$24

Computer Programming Lab #4 Solved

    1. void russian_multiplication (unsigned int* multiplicand, unsigned int* multiplier): Write a function that multiplies two numbers using the Russian Peasant Multiplication Algorithm and returns the result in parameter multiplicand. The second parameter should return the latest multiplier calculated by the algorithm. Your function should return 5402 for multiplicand 37 and multiplier 146 and print the following for the example in the given table:

37 * 146 = 74 + 592 + 4736 = 5402

Multiplier = 1

Note: The latest value of the multiplicand and the multiplier should only be printed in main().

Multiplicand
Multiplier
Is current multiplier is odd?



37
146
146 mod 2 = 0 => Ignore



74
73
73 mod 2 = 1 => +74



148
36
36 mod 2 = 0 => Ignore



296
18
18 mod 2 = 0 => Ignore



592
9
9 mod 2 = 1 => +592



1184
4
4 mod 2 = 0 => Ignore



2368
2
2 mod 2 = 0 => Ignore



4736
1
Ignore






    2. void multiply_polynomials (double* a3, double* a2, double* a1, double* a0, double* b3, double* b2, double* b1, double b0): Write a function that multiplies two 3rd degree polynomials given by (a3, a2, a1, a0) and (b3, b2, b1, b0) and obtains a 6th-degree polynomial with given by (a3, a2, a1, a0, b3, b2, b1). You have to print the result in main().

Note: Remember that product of two 3rd degree polynomial can have at most 7 terms.

More products