fork download
  1. #include <time.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5.  
  6.  
  7. int rand7(void)
  8. {
  9. const int ret[][2] = {
  10. {2, 1}, {3, 2}, {5, 3}, {6, 4}, {8, 5}, {10, 6}, {12, 7}
  11. };
  12. srand((unsigned)time(NULL));
  13. int a = rand() % 5 + 1;
  14. int b = rand() % 5 + 1;
  15. int i;
  16. for (i = 0; i < 7; i++) {
  17. if (a*b == ret[i][0]) {
  18. return ret[i][1];
  19. }
  20. }
  21. return 0;
  22. }
  23.  
  24. int main(void)
  25. {
  26. int num = 0;
  27. while (num == 0) {
  28. num = rand7();
  29. }
  30. printf("%d\n", num);
  31. return 0;
  32.  
  33. }
Success #stdin #stdout 0.02s 1676KB
stdin
Standard input is empty
stdout
6