Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- #include <ctime>
- using namespace std;
- int main(int argc, char** argv) {
- int a,b,c,min;
- cout<<"Podaj ile liczb chcesz losowac: ";
- cin>>a;
- cout<<"Podaj maksymalna wartosc wylosowanych liczb: ";
- cin>>b;
- cout<<"Podaj minimalna wartosc wylosowanych liczb:";
- cin>>c;
- b++;
- min=b-c;
- int d[a],i,j,pmin,x,p;
- cout<<endl;
- if(b>=c){
- do{
- p=0;
- for(i=0;i<a;i++)d[i]=(rand()%min)+c;
- for(i = 0; i < a; i++) cout << " " << d[i];
- for(i=0;i<a;i++){
- for(x=i;x<a;x++){
- if(i==x)x++;
- if(d[i]==d[x]){
- p=1;
- }
- }
- }
- }while(p==1);
- for(j = 0; j < a - 1; j++){
- pmin = j;
- for(i = j + 1; i < a; i++)
- if(d[i] < d[pmin]) pmin = i;
- swap(d[pmin], d[j]);
- }
- cout << "\n\nPo sortowaniu:\n\n";
- for(i = 0; i < a; i++) cout << " " << d[i];
- }
- else(cout<<"brak liczb");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement