I have been trying for some time now, but i can't figure it out. I have to make a program where in a matrix, it finds the top, bottom, left and right numbers and prints them out. I made it where it prints the bottom, left and right numbers but can't figure out how to print the top one.
#include <iostream>
using namespace std;
int main()
{
int a[10][10],i,j,m,n,zb,zb2,zb3,zb4;
cin>>m>>n;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
cin>>a[i][j];
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(i+j<m-1){
zb=a[i][j]; // first
}
if(i+j<m+1){
zb2=a[i][j]; // second
}
if(i<j){
zb3=a[i][j]; // third
}
if(n+m<j+1){
zb4=a[i][j]; // fourth
}
}
}
cout<<zb<<endl;
cout<<zb2<<endl;
cout<<zb3<<endl;
cout<<zb4<<endl;
return 0;
}
A Graph of how the program works Example of program
Thank you in advance!