Anonymous user
Ethiopian multiplication: Difference between revisions
Undo revision 113931 by Ledrug (Requirements stipulate halve, double, iseven).
(→{{header|C}}: cleanup) |
(Undo revision 113931 by Ledrug (Requirements stipulate halve, double, iseven).) |
||
Line 390:
=={{header|C}}==
<lang c>#include <stdio.h>
#include <stdbool.h>
int ethiopian(int left, int right)▼
void halve(int *x) { *x >>= 1; }
void doublit(int *x) { *x <<= 1; }
bool iseven(const int x) { return (x & 1) == 0; }
int plicand, const bool tutor)
{
if (tutor)
if (left & 1) result += right;▼
while(plier >= 1) {
if ( iseven(plier) ) {
return result;▼
if (tutor) printf("%4d %6d struck\n", plier, plicand);
} else {
if (tutor) printf("%4d %6d kept\n", plier, plicand);
}
halve(&plier); doublit(&plicand);
}
}
int main()
{
}</lang>
|