Question: This code finds the first row of an n-by-n integer matrix named x that has nothing but 0 values. Here is the code in C.
This code finds the first row of an n-by-n integer matrix named x that has nothing but 0 values. Here is the code in C.
include
int main(void)
{
int x[4][4] = {{0, 0, 0, 0},{0, 1, 2, 3}};
int n=4;
int i, j;
int r=-1;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++){
if (x[i][j] != 0){
goto reject;
}
}
r=i;
break;
}
reject: printf (" First all-zero row is: %d", r);
return 0;
}
Rewrite this code without gotos in C++, Java, or C#. If you can explain how I would go about solving this I would greatly appreciate it.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
