max prime in a 2D array bug

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;
Move the first line down two lines.
once the flag becomes '0', it remains same.
you need to change it to '1' to search for next prime number.
at line 14, before '}' put
flag =1;
@Ultralegendary
thank you , it worked. i get it now :)
Topic archived. No new replies allowed.