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 = 0;
  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. do
  26. {
  27. if (multiply(a, b) != a * b)
  28.  
  29.  
  30. fprintf(stderr,
  31. "ERROR:\n"
  32. "my: %u\n"
  33. "norm: %u\n"
  34. "%hu * %hu\n"
  35. "\n",
  36. multiply(a, b), (a * b),a, b
  37. );
  38.  
  39. if (USHRT_MAX == a)
  40. {
  41. b++;
  42. }
  43. a++;
  44. //fprintf(stderr, "%hu * %hu\n", a, b);
  45. } while ( ( a != 0 ) || (b != 0) );
  46.  
  47. fprintf(stderr, "%hu * %hu\n", a, b);
  48. printf("Done!\n");
  49.  
  50. return 0;
  51. }
Time limit exceeded #stdin #stdout 5s 1784KB
stdin
Standard input is empty
stdout
Standard output is empty