Anonymous user
Ethiopian multiplication: Difference between revisions
→{{header|D}}
Line 622:
=={{header|D}}==
Works with DMD V.2.051.
<lang d>import std.stdio: writeln;
pure nothrow int ethiopian(int n1, int n2)
in {
assert(n1 >= 0, "muliplier cannot be negative");
} body {
static pure nothrow int doubleNum(const int n)
static pure nothrow int halveNum(const int n)
static pure nothrow bool isEven(const int n)
int result;
while (n1 >= 1) {
if (!isEven(n1))
Line 640 ⟶ 641:
n2 = doubleNum(n2);
}
return result;
}
|