I don't understand your while. Don't you want a if instead?
for(i=0;i<12;i++) {
c=0;
for (j=0;j<26;j++) {
if(grid[i][j]!=500.00 && c<=ncmax) {
c++;
} else {
printf("%d \n \n",c);
}
}
}
But I think you could go for something simpler:
for(i=0;i<12;i++) {
for (j=0;j<26;j++) {
if(grid[i][j]==500.00) {
printf("%d %d \n \n",i , j);
}
}
}
EDIT:
I just noticed that in the first program, c
and j
have the same value. You could simplify to:
for(i=0;i<12;i++) {
c=0;
while(c<26 && c<=ncmax && grid[i][c]!=500.00) {
c++;
}
printf("%d \n \n",c);
}
The output should be the list of c
. It is equals to the minimum of 26
or ncmax+1
or the index of the value 500.00
in the line i
.
PS: If you know the value of ncmax
, you could simplify the condition.