Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions C++/boxpattern
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<iostream>
using namespace std;

int main() {
int n, i, j, p;
cin >> n;
int a[100][100] = {0};
int top = 0, btm = 2 * n - 2, lt = 0, rt = 2 * n - 2;
int value = n; // New variable to hold the value

while (value >= 1) {
for (i = lt; i <= rt; i++) {
a[top][i] = value;
a[btm][i] = value;
}
for (i = top; i <= btm; i++) {
a[i][lt] = value;
a[i][rt] = value;
}
top++;
btm--;
lt++;
rt--;
value--; // Decrement the value as you move outwards
}

for (i = 0; i < 2 * n - 1; i++) {
for (j = 0; j < 2 * n - 1; j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}