How to find the minimum and maximum of a 2d array c++
Hey guys, Where is the problem with my code?? sometimes it doesn't give me the correct answer... #include <iostream> using namespace std; int main() { int A[2][2]; int Min, Max; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { cin>>A[i][j]; } } for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { cout<<A[i][j]<<" "; if (A[i][j] >= A[0][0]) { Max = A[i][j]; } if (A[i][j] <= A[0][0]) { Min = A[i][j]; } } cout<<endl; } cout<<"Max: "<<Max<<endl; cout<<"Min: "<<Min<<endl; return 0; }