#include <stdio.h>
unsigned int multiplier_fun(unsigned int mulcand, unsigned int mul)
{
unsigned int max_num, i, total;
if ((mulcand == 0) || (mul == 0))
return 0;
for (max_num = 31; max_num > 0; max_num--)
{
if (mul & (1 << max_num))
break;
}
total = 0;
for (i = 0; i <= max_num; i++)
{
if (mul & (1 << i))
{
total += (mulcand << i);
}
}
return total;
}
int main()
{
unsigned int var_a, var_b;
printf("\nPlease input a and b values:");
scanf("%d %d", &var_a, &var_b);
printf("\n=============================================\n");
printf("%d x %d = %d", var_a, var_b, multiplier_fun(var_a, var_b));
printf("\n=============================================\n");
return 0;
}
Please input a and b values:9 19
=============================================
9 x 19 = 171
=============================================
Please input a and b values:3 133
=============================================
3 x 133 = 399
=============================================
沒有留言:
張貼留言