#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int N,A[8];
cout<<"Enter the number:";
cin>>N;
srand(time(0));
for(int i=1;i<=8;i++)
{
A[i]=rand()%40+10;
for(int j=0;j<1;j++)
{
cout<<A[i];
}
cout<<" ";
}
return 0;
}
basom
0
Newbie Poster
Recommended Answers
Jump to PostTo generate integers between 10 and 40 inclusive you can use:
rand()%31 + 10;
By N DISTINCT random integers, I assume that it means N different integers. So you'd have an array[N] and keep
generating random range numbers, check if they're already present in the array …
All 2 Replies
basom
0
Newbie Poster
nullptr
167
Occasional Poster
TrustyTony
commented:
Good thinking of mathematical consequences of uniqueness: ' not more than the number of integers between 10 and 40 inclusive'
+12
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.