Ethiopian multiplication: Difference between revisions
Content added Content deleted
(→{{header|C}}: cleanup) |
(Undo revision 113931 by Ledrug (Requirements stipulate halve, double, iseven).) |
||
Line 390: | Line 390: | ||
=={{header|C}}== |
=={{header|C}}== |
||
<lang c>#include <stdio.h> |
<lang c>#include <stdio.h> |
||
#include <stdbool.h> |
|||
⚫ | |||
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) |
|||
{ |
{ |
||
int result=0; |
|||
for (; left; left >>= 1, right <<= 1, printf("\n")) { |
|||
printf("%4d %6d", left, right); |
|||
if (tutor) |
|||
⚫ | |||
printf("ethiopian multiplication of %d by %d\n", plier, plicand); |
|||
} |
|||
while(plier >= 1) { |
|||
printf("-------------\n %5d\n", result); |
|||
if ( iseven(plier) ) { |
|||
⚫ | |||
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() |
int main() |
||
{ |
{ |
||
printf("%d\n", ethiopian(17, 34, true)); |
|||
return 0; |
|||
}</lang> |
}</lang> |
||