Ethiopian multiplication: Difference between revisions
Content added Content deleted
(Updated D entry) |
|||
Line 926: | Line 926: | ||
=={{header|D}}== |
=={{header|D}}== |
||
⚫ | |||
⚫ | |||
⚫ | |||
in { |
in { |
||
assert(n1 >= 0, " |
assert(n1 >= 0, "Multiplier can't be negative"); |
||
} body { |
} body { |
||
static |
static enum doubleNum = (in int n) pure nothrow => n * 2; |
||
static |
static enum halveNum = (in int n) pure nothrow => n / 2; |
||
static |
static enum isEven = (in int n) pure nothrow => !(n & 1); |
||
int result; |
int result; |
||
Line 945: | Line 943: | ||
return result; |
return result; |
||
⚫ | |||
} |
|||
⚫ | |||
assert(ethiopian(77, 54) == 77 * 54); |
assert(ethiopian(77, 54) == 77 * 54); |
||
assert(ethiopian(8, 923) == 8 * 923); |
assert(ethiopian(8, 923) == 8 * 923); |
||
Line 954: | Line 950: | ||
void main() { |
void main() { |
||
⚫ | |||
writeln("17 ethiopian 34 is ", ethiopian(17, 34)); |
writeln("17 ethiopian 34 is ", ethiopian(17, 34)); |
||
}</lang> |
}</lang> |
||
{{out}} |
|||
Output: |
|||
<pre>17 ethiopian 34 is 578</pre> |
<pre>17 ethiopian 34 is 578</pre> |
||