fork(1) download
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4.  
  5. int main(void) {
  6. int Array[10];
  7. int i = 0;
  8. srand ( time(NULL) );
  9. while (i != 6) {
  10. int candidate = ((rand() % 49) + 1);
  11. int ok = 1; // ok will become 0 if a duplicate is found
  12. for (int j = 0 ; ok && j != i ; j++) {
  13. ok &= (candidate != Array[j]);
  14. }
  15. if (ok) {
  16. Array[i++] = candidate;
  17. printf("%d ", candidate);
  18. }
  19. }
  20. }
  21.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
28 4 48 44 42 8