Hi all.
I'm trying to make a program where there is an array of 20 elements. Now, numbers from 1 to 20 will be assigned in a random order in the array.
This is my code:-
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
int i,j,random_integer,count=0,sno[20];
srand((unsigned)time(0));
sno[0]=(rand()%20)+1;
for(i=0;i<=19;i++)
{
lbl1: random_integer=(rand()%20)+1;
for(j=1;j<=i;j++)
{
if(sno[j]==random_integer)
break;
count++;
}
if(count==i)
sno[i]=random_integer;
else
goto lbl1;
}
for(i=0;i<=19;i++)
cout<<"\n"<<sno[i];
}
When I execute this code in Turbo c++, Turbo c++ hang.
What is wrong with this code?