c++ generating random numbers without repetition .output screen is just
blank with a blinking cursor
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int randrange(int low,int high)
{
return rand()%(low+high)+low+1; }
int main()
{
int num[9]={0},i,j;
bool check;
for(i=0;i<9;i++)
{
check=false;
do
{
num[i]=randrange(1,9);
for(j=0;j<i;j++)
{
if( num[i]==num[j])
check=false;
else
check=true;
}
}while(check==false);
}
for(i=0;i<9;i++)
{
cout<<num[i]<<" ";
}
return 0;
}
No comments:
Post a Comment