Any help would be much appreciated with this problem I've been having. I'm trying to create a loop to find a 30x30 array whose main diagonal values are all greater or equal than 7. The arrays are filled with random integers.
My issue is the loop itself, I can't seem to figure out how to create such a large series of loops.. driving me nuts!
When I've managed to create an array that meets the criteria, I need to display how many attempts it took. If it takes more than 1 million attempts, the program should simply "give up", displaying that it is not possible.
This is what i've managed to come up with so far (not the entire code, just the bit I need help with), however the output is literally nothing. I guarantee I'm not even close to the right solution... but I would appreciate a point in the right direction!
Thanks in advance :)
count=0;
for(a=0;a<30;++a)
for(b=0;b<30;++b)
random2[a][b]=rand()%10;
while(count<=1000000)
{
for(a=0;a<30;++a)
{
if(random2[a][a]>=7)
{
++a;
if(a==30&&random2[a][a]>=7)
printf("%d", count);
}
else
{
++count;
for(a=0;a<30;++a)
for(b=0;b<30;++b)
random2[a][b]=rand()%10;
}
}
}
printf("%d", count);