-1
#include<stdio.h>
int main ( void ){
int row;
int column;
for ( row = 1; row <= 7; row++ ){
for (column = 1; column <= row; column++ )
printf("*");
printf("\n");
} printf("\n");
}
I want to know if the loop for can be used without {
after your argument?
Is it possible to translate this code for me? ' loop coming out of the first for
, verifying the condition of the second and giving print after that it will add in column
and return to add in row
also and staying row = 2
and column = 2
, this way will give one more print.
The problem is that if so, this second loop would no longer agree with the figure since the printf
is only triggered when column <= row
.
How this piece of code works?
The program starts and releases * as output because column <= row = TRUE
( both are 1), then 1 is added to the column
, making column < = row = FALSE
, the program leaves the loop internal and skips a line, adding 1 to Row and making again column (2) <= row(2) = TRUE
, because of this the program will release one more * in the line below and after that will add +1 to the column
and make olumn(3) <= row(2) = FALSE
, causing him to leave the loop internal and go to the external loop.
With that thought I’m imagining you’ll graduate a vertical row of * since column
is only -1 that row
, always, when this -1 ceases to exist with the increment of the loop internal, a line is added by loop external, in this way, does not even form the pattern.
Program starts. column < Row = FALSE, program skips a line, Row is added 1. column < Row = TRUE, program releases () like print, column is added 1, column < Row = FALSE, program skips a line, Row is added 1. column (1) < Row (2) = TRUE, program releases () like print, 1 is added to the column by making column < Row = FALSE, program skips one more line, Row is added plus 1. Notice the problem of the way I’m seeing? that way the column will always be a value more than the Row and if it is that way until now would be *
– Vitor Matos
within () is to be * and the last two * * * is vertical
– Vitor Matos
GUY! I was breaking my head here, but I think maybe this is the reason I’m not understanding: the column value after incrementing in +1 inside the loop until the condition is false is, after exiting the loop, reset right?
– Vitor Matos
I’m sorry, but it’s very difficult to understand the things you write, it’s almost ciphertext, it seems that you want to summarize so much that you eat important pieces. Perhaps this also occurs with your understanding. What you described doesn’t make any sense, so much so that I don’t even know where to start to say what’s wrong.
– Maniero
I think I figured out where I was going wrong. I thought the value incremented to the variable column was saved inside the loop, so it wouldn’t work. But the code works precisely pq when I exit the internal loop and go to the external column value back to 0. anyway you helped me because you showed me a more tidy code and asked questions regarding the use of FOR, besides giving test tips. Thank you.
– Vitor Matos