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. while (a) {
  12. res <<= 1;
  13. if (a & 1) {
  14. res += b;
  15. }
  16. a >>= 1;
  17. }
  18. return res;
  19. }
  20.  
  21. void example_mul(uint16_t a, uint16_t b) {
  22. printf("%d*%d = %d\n", a, b, mul(a, b));
  23. }
  24.  
  25. int main() {
  26. example_mul(5, 6);
  27. example_mul(7, 4);
  28. example_mul(3, 21);
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 4360KB
stdin
Standard input is empty
stdout
5*6 = 30
7*4 = 28
3*21 = 63