Anonymous user
Ethiopian multiplication: Difference between revisions
→{{header|D}}: add implementation
(typo fix in CL multiple/multiply) |
(→{{header|D}}: add implementation) |
||
Line 210:
(r r (double r)))
((zerop l) product))))</lang>
=={{header|D}}==
<lang d>
import std.stdio;
int dub(int num) {return num<<1;}
int halve(int num) {return num>>1;}
bool isEven(int num) {return !(num&1);}
int ethiopian(int n1,int n2) {
int ret = 0;
while(n1>=1) {
if (!isEven(n1)) ret += n2;
n1 = halve(n1);
n2 = dub(n2);
}
return ret;
}
int main() {
writefln("17 ethiopian 34 is %d",ethiopian(17,34));
return 0;
}
</lang>
=={{header|E}}==
|