I have a little difficulty in programming in C ++ to make patterned output using 2D arrays, I make the output like a matrix like this: input 4 (for column 4 & row 4)
I I I I
0 0 I 0
0 I 0 0
I I I I
I've tried this my programmed. For the top and bottom rows I've managed to change the value to 1
#include <iostream>
using namespace std;
int main(){
int elemen[100][100], n, i, j, k;
cout <<"input element = ";
cin >>n;
for(i = 0;i < n;i++){
for(j = 0;j < n;j++){
elemen[0][j] = 1;
elemen[n-1][j] = 1;
elemen[n-i][n-j] = 1;
cout <<elemen[i][j]<<" ";
}
cout<<endl;
}
}
but the output that occurs in the above program is like this:
I I I I
0 0 0 0
0 0 I I
I I I I
whereas logically it is correct, and I've tried it on non-input arrays.whereas logically it is correct, and I've tried it on non-input arrays. because if we input the array element = 5, then the loop will automatically reduce the value of 5 one by one. Is there anyone who can help, sorry if you do not understand, because I am currently still learning to hone my logic