fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <limits.h>
  4.  
  5. unsigned int multiply (unsigned short a, unsigned short b)
  6. {
  7. register unsigned int result = 0;
  8. char n;
  9.  
  10. for (n = 0; b & (1 << n); n++)
  11. {
  12. if ( b & (1 << n) )
  13. result += a << n;
  14. }
  15. return result;
  16. }
  17.  
  18. int main(void)
  19. {
  20.  
  21. unsigned short a, b;
  22. a = 0;
  23. b = 0;
  24.  
  25. {
  26. if (multiply(a, b) != a * b)
  27. {
  28. fprintf(stderr,
  29. "ERROR:\n"
  30. "my: %u\n"
  31. "norm: %u\n"
  32. "\n",
  33. multiply(a, b), a * b
  34. );
  35. }
  36. if (USHRT_MAX == a)
  37. {
  38. b++;
  39. }
  40. a++;
  41.  
  42. } while ( (a != 0) && (b != 0) );
  43.  
  44. printf("Done!");
  45.  
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0s 1788KB
stdin
Standard input is empty
stdout
Done!