Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please make sure to match the example above, thank you so much! Write a C progra

ID: 3831150 • Letter: P

Question

Please make sure to match the example above, thank you so much!

Write a C program called mult.c that implements multiplication on two unsigned integers. You cannot use the multiplication operator (*) in your solution Arguments should be accepted from the command line 1. The first argument is the multiplicand (the a in a * b) 2. The second argument is the multiplier (the b in a * b) Your program must complete in 0(1) (constant) time 1. 0(1) means that you can find a constant value C such that you can guarantee that the program will run in no more than C iterations 2. This is possible because an integer is 32 bits long and so the loop that does the multiplication should not take longer than 32 iterations. 3. Because of this restriction the following solution is not acceptable as it does not meet the O requirements unsigned long long bad_mult(unsigned int a, unsigned int b){unsigned long long product = 0; for(int i = 0; i

Explanation / Answer

Hi,

I have made used of recursion and bitwise operator to find the multiplication of two numbers:-

The code is self descriptive.Please find the code below:-

CODE:-

#include<stdio.h>

int sum(int no1, int no2);

int main() {

unsigned long long int no1, no2, multi = 0;

int i;

printf ("Enter first number ");

scanf("%11u", &no1);

printf("Enter second number ");

scanf("%11u", &no2);

/* Add no1 to itself, no2 times */

for (i = 0; i < no2; i++) {

multi = sum(multi, no1);

}

printf("Multiplication of %11u and %11u is %11u ", no1, no2, multi);

return 0;

}

/* Add two numbers using bitwise operators */

int sum(int no1, int no2) {

unsigned long long int carr;

while (no2 != 0) {

carr = (no1 & no2) << 1;

/* calculating the sum */

no1 = no1 ^ no2;

no2 = carr;

}

return no1;

}

===============================================================================

The output will be:-

Enter first number 134518988
Enter second number 134514210
Multiplication of 134518988 * 134514210 is 13817095824448361240

=============================================================================

Please let me know in case any clarification required