Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4.  
  5.  
  6. int main()
  7. {
  8.     int *tab,i,j,a,b,n;
  9.     printf("ten program losuje n liczb bez powtorzen\n");
  10.     printf("Podaj ile liczb chcesz wylosowac:\n");
  11.     scanf("%d", &n);
  12.     tab=malloc(n*sizeof(int));
  13.     srand(time(NULL));
  14.  
  15.      do{
  16.        printf("Podaj granice przedzialu min i max\n");
  17.         scanf("%d %d", &a,&b);
  18.     }while(a>b||(b-a<n));
  19.  
  20.     for(i=0;i<n;i++)
  21.     {
  22.         *(tab+i)=a+rand()%(b-a+1);
  23.         for(j=0;j<i;j++)
  24.         {
  25.           if(*(tab+i)==*(tab+j))
  26.             i--;
  27.         }
  28.     }
  29.  
  30.     for(i=0;i<n;i++)
  31.     {
  32.         printf("%d ", *(tab+i));
  33.     }
  34.     free(tab);
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement