I have the simplest logic for border elements !!! I will post it if anyone's interested !!! The simplest logic for BORDER/BOUNDARY ELEMENTS of a Matrix is here: #include<iostream.h> int A[10][10],i,j,m,n; cout<<"Enter the number of rows and columns\n"; cin>>m>>n; for(i=0,i<m;i++) for(j=0;j<n;j++) cin>>A[j]; for(i=0;i<m;i++) for(j=0;j<n;j++) if(((i==0)||(j==0))||((i==m-1)||(j==n-1))) cout<<A[j]<<"is a BORDER ELEMENT\n"; } Instead of using 4 nested for loops ,you can use this logic -Just one nested for loop enclosing the single-line LOGIC!!! HOPE THIS WAS USEFUL!!!