Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int array[40];
- int num, val;
- bool found=false;
- for(int c=0;c<40;c++)
- {
- val=rand()%40+1;
- for(int x=0;x<40;x++)if(val==array[x])found=true;
- if(found==false)array[c]=val;
- else c--;
- found=false;
- }
- cout<<"Give an amount of numbers to be generated (Between 1 and 20) ";
- cin>>num;
- while(num>20||num==0)
- {
- cout<<"Invalid number, please choose a number between 1 and 20 ";
- cin>>num;
- }
- for(int c=0;c<num;c++)cout<<array[c]<<", ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement