fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. uint16_t mul(uint16_t a, uint16_t b) {
  5. uint16_t res = 0;
  6.  
  7. if (!a || !b) {
  8. return 0;
  9. }
  10.  
  11. int i = 0;
  12. while (i < 16) {
  13. if (a & (1 << i)) {
  14. res += b;
  15. }
  16. b <<= 1;
  17. i++;
  18. }
  19. return res;
  20. }
  21.  
  22. void example_mul(uint16_t a, uint16_t b) {
  23. printf("%d*%d = %d\n", a, b, mul(a, b));
  24. }
  25.  
  26. int main() {
  27. example_mul(5, 6);
  28. example_mul(7, 4);
  29. example_mul(3, 21);
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 4188KB
stdin
Standard input is empty
stdout
5*6 = 30
7*4 = 28
3*21 = 63