I will not even try to solve the problem in this code because it is too confusing and maybe the problem was born of confusion. The simpler you can do, the better. Even if you want to learn some specific concept with this type of code, it is best to learn in a case where it would be needed. If someone asked to do it this way, the person did a disservice to you. It would be a useless and unproductive requirement. and I would argue that this form is disadvantageous.
Do not declare variables out of function unnecessarily . Always declare as close as possible to where it will be used. There are people who do not see the value of this, but it creates a greater cognitive ability to do simpler things. If you need the variable just inside the loop, create it inside the loop .
If you have two vectors to consider, create two loops, which is the natural way to do this. This is the structured way to make this code. The original knotted the head. Even a for
loop is much more natural for the case.
There was a column variable of type char
. Or it makes the line also char
and limits the number of asterisks to 127, leaves int
in both. I left int
because there is no real gain in using char
there, even if it only wants low values, which is not even validated, either because scanf()
is not very suitable for this . Be consistent.
I gave an organized one. It is very difficult to understand what the code does in written form.
Once this is done, the code becomes too simple.
#include<stdio.h>
int main(void) {
printf("TELL ME THE NUMBER YOU WANT: \n");
int n;
scanf("%d", &n);
for (int row = 0; row < n; row++) {
for (int column = 0; column < n; column++) {
printf("*");
}
printf("\n");
}
}
See running on ideone and on Coding Ground >.