0
#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;
}
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by nullptr
0

the quetion as the following
write a program that prompts the user to enter a number N then generates N DISTINCT random integers between 10 and 40 inclusive and stores them in array A the program will prints the elements of the array
i wish to help me solve this question

1

To 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 and if not place the number in the array until you reach array[N - 1]
You would also want to validate that the number N entered is not more than the number of integers between 10 and 40 inclusive.

Edited by nullptr

Votes + Comments
Good thinking of mathematical consequences of uniqueness: ' not more than the number of integers between 10 and 40 inclusive'
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.