fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <limits.h>
  4. #include <inttypes.h>
  5.  
  6. uint32_t multiply (uint16_t a, uint16_t b)
  7. {
  8. //uint16_t mask = 0b0000000000000001;
  9.  
  10. register uint32_t result = 0;
  11. char n = 0;
  12. /*
  13.   for (n = 0; b >= (1 << n); n++)
  14.   {
  15.   if ( b & (1 << n) )
  16.   result += a << n;
  17.   }*/
  18. if ( b & (1 << n) )
  19. result += a << n;
  20. n++;
  21. if ( b & (1 << n) )
  22. result += a << n;
  23. n++;
  24. if ( b & (1 << n) )
  25. result += a << n;
  26. n++;
  27. if ( b & (1 << n) )
  28. result += a << n;
  29. n++;
  30. if ( b & (1 << n) )
  31. result += a << n;
  32. n++;
  33. if ( b & (1 << n) )
  34. result += a << n;
  35. n++;
  36. if ( b & (1 << n) )
  37. result += a << n;
  38. n++;
  39. if ( b & (1 << n) )
  40. result += a << n;
  41. n++;
  42. if ( b & (1 << n) )
  43. result += a << n;
  44. n++;
  45. if ( b & (1 << n) )
  46. result += a << n;
  47. n++;
  48. if ( b & (1 << n) )
  49. result += a << n;
  50. n++;
  51. if ( b & (1 << n) )
  52. result += a << n;
  53. n++;
  54. if ( b & (1 << n) )
  55. result += a << n;
  56. n++;
  57. if ( b & (1 << n) )
  58. result += a << n;
  59. n++;
  60. if ( b & (1 << n) )
  61. result += a << n;
  62. n++;
  63. if ( b & (1 << n) )
  64. result += a << n;
  65. return result;
  66. }
  67.  
  68. int main(void)
  69. {
  70.  
  71. uint16_t a, b;
  72. a = 0;
  73. b = 0;
  74.  
  75. do
  76. {
  77. if (multiply(a, b) != a * b)
  78.  
  79.  
  80. fprintf(stderr,
  81. "ERROR:\n"
  82. "my: %u\n"
  83. "norm: %u\n"
  84. "%hu * %hu\n"
  85. "\n",
  86. multiply(a, b), (a * b),a, b
  87. );
  88.  
  89. if (UINT16_MAX == a)
  90. {
  91. b++;
  92. }
  93. a++;
  94. //fprintf(stderr, "%hu * %hu\n", a, b);
  95. } while ( ( a != 0 ) || (b != 0) );
  96.  
  97. fprintf(stderr, "%"PRIu16"* ""%"PRIu16"\n", a, b);
  98. printf("Done!\n");
  99.  
  100. return 0;
  101. }
  102.  
Time limit exceeded #stdin #stdout 5s 1828KB
stdin
Standard input is empty
stdout
Standard output is empty