This is my program, it represents the Russian “peasant” way of multiplication, at the moment it works a little differently than I want. Please tell me how I can fix it? There are mandatory input data, as well as mandatory output data.
int rusMult(int a, int b)
{
if (b <= 0)
{
return rusMult(a, -b);
}
if (b == 0)
{
return 0;
}
else
{
if (b % 2 == 0)
{
rusMult(a * 2, b / 2);
}
else
{
rusMult(a * 2, b / 2) + a;
}
}
if (b > 0)
{
printf("%dt %dtn", a, b);
int res = rusMult(a * 2, b / 2);
int ost = b % 2;
printf("%dt %dt %dt %dtn", a, b, ost, res);
if (ost == 1)
{
res += a;
}
rusMult(a * 2, b / 2);
}
}