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