Advertisement
Lisaveta777

Populate array unique

Nov 7th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #define SIZE 20
  5.  
  6. //populate an array of given SIZE with unique numbers from 0 to SIZE-1.use rand()
  7.  
  8. void pop_arr(int *,int);
  9. void pr_arr(int *, int);
  10. void is_it_repeat(int *,int,int);
  11.  
  12. int main()
  13. {
  14.     int arr[SIZE];
  15.     pop_arr(arr,SIZE);
  16.     pr_arr(arr,SIZE);
  17.  
  18.     return 0;
  19. }
  20. void pr_arr(int *a,int s)
  21. {
  22.     int i;
  23.     for(i=0;i<s;i++)
  24.         printf("%d\t",a[i]);
  25.     printf("\n");
  26. }
  27. void pop_arr(int *a,int s)
  28. {
  29.     int i,j,counter=0;
  30.     for(i=0;i<s;i++)
  31.     {
  32.         printf("counter %d\n",counter);
  33.         counter++;
  34.         a[i] = rand()%SIZE;
  35.         printf("\nvalue %d\t",a[i]);
  36.         {
  37.             for(j=0;j<=i-1;j++)//here suppose to start function
  38.             {
  39.                 if(a[i]==a[j])
  40.                     j = i,i--,printf("try once more!");
  41.             }
  42.         }
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement