Hello, i have a problem with an infinite loop.
I have got 4 arrays , each of them, have 5 integers
the elements are from random funtcion, I don't want to have same elements in the arrays so i make an if in line 18.The problem:some times the code prints me the 5 elements of d[i] and some times not(it starts to run but it doesn't do no anything- i think tha is an infinite loop)
I have got 4 arrays , each of them, have 5 integers
the elements are from random funtcion, I don't want to have same elements in the arrays so i make an if in line 18.The problem:some times the code prints me the 5 elements of d[i] and some times not(it starts to run but it doesn't do no anything- i think tha is an infinite loop)
Code:
int a[5];
int b[5];
int c[5];
int d[5];
i = 0;
k=0;
z=0;
while(i<6)
{
t = rand()%100 +1 ;
if (t!=100 && t!=1)
{
while(z<6)
{
if(a[z]!=t && b[z]!=t)
{
k=1;
}
else k=0;
z++;
}
if(k==1)
{
if(c[i]>t)
{
d[i]=t;
i++;
}
}
}
}
printf("answers\n");
for(i = 0 ; i < 5 ; i++)
printf("%d\n" , d[i]);
Comment