Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <windows.h>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int losuj(int ilosc,int poczatek, int koniec)
  9. {
  10.     int *tab;
  11.     tab = new int[ilosc];
  12.     bool check;
  13.     int liczba;
  14.     srand(time(NULL));
  15.      for (int i=1; i<=ilosc; i++)
  16.       {
  17.         do
  18.         {
  19.             liczba = rand()% (poczatek-koniec)+poczatek;
  20.             check=true;
  21.             for (int j=0;j<i;j++)
  22.                 if (liczba == tab[j] )
  23.                 {
  24.                     check=false;
  25.                 }
  26.         } while (!check);
  27.  
  28.             tab[i]=liczba;
  29.             cout<<tab[i]<<endl;
  30.  
  31.       }
  32.  
  33.  
  34.    return tab[i];
  35. }
  36.  
  37. int main()
  38. {
  39.   int ilosc;
  40.   int poczatek;
  41.   int koniec;
  42.   int *tab;
  43.   tab = new int[ilosc];
  44.  
  45.     cout << "Czesc, podaj ile liczb wyloscowac:"<< endl;
  46.     cin>>ilosc;
  47.  
  48.     cout<< "Podaj poczatek przedzialu: "<<endl;
  49.     cin>>poczatek;
  50.  
  51.     cout<< "Podaj koniec przedzialu: "<<endl;
  52.     cin>>koniec;
  53.     cout<<endl;
  54.  
  55.     tab[i]=losuj(int ilosc, poczatek, int koniec);
  56.  
  57.     delete [] tab;
  58.  
  59.  
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement