I have an exercise I need to submit. The user should enter 2 numbers, one of height and one of width, and the output should be a rectangle that the outer numbers are low and the inner ones are high. So I wrote it but it does not work in some numbers, for example 9 and 3, but in most things it works. I made 2 variables that are equal to the numbers entered by the user, this data goes down, the other 2 variables are just indicators, of the loops, they have no meaning If anyone has a different direction how to do it, I would love to hear, just in loops ..
For example:
1 1 1 1 1 1 1 1 1
1 2 2 2 2 2 2 2 1
1 2 3 3 3 3 3 2 1
1 2 3 3 3 3 3 2 1
1 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 1
Thanks
#include <stdio.h>
int main() {
int row, col, u, d;
scanf("%d", &row);
scanf("%d", &col);
int row_1, col_1;
for (u = 1, row_1 = row; u <= row; u++, row_1--) {
for (d = 1, col_1 = col; d <= col; d++, col_1--) {
if (col_1 < u && row_1 > col_1)
printf("%d", col_1);
else if (u > d && row_1 >= d)
printf("%d", d);
else if(row_1 > u)
printf("%d", u);
else
printf("%d", row_1);
}
printf("\n");
}
return 0;
}