i have this part of a program code, which purpose is to find max prime num in a 2D array.
it should work fine.. but for some reason it only checks the first row,
so the output will be the max prime of the first row only ?
anyone can see through this ? what's seems to be the prob ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
flag=1;
for (int i = 0;i < size2;i++) {
for (int j = 0;j <size2;j++) {
for (int k = 2;k < ar[i][j];k++) {
if (ar[i][j] % k == 0)
{
flag = 0;
}
}
if (flag) {
if (ar[i][j] > max)
max = ar[i][j];
}
}
}
cout << "max prime = " << max<<endl;