nesting loops

Hi i have the following qustion to answer

how can i find the output of this code

for (int row=1;row<=9;++row)
for (int col=1;col<=row;++col)

cout <<"*";
cout <<"\n";

I need someone to give me the output with explanation please.
Why don't you run the code to see your the output yourself?

Anyway. The outer for loop contains two instructions: the inner for loop and cout <<"\n"; which outputs a newline.
The inner for loop contains a single instruction cout <<"*"; which outputs an asterisk.

Edit: meh.
Last edited on
thank you
yeah i'm trying to see the output but I didnt know from where
when I click run I get a black screen and then disappear
Last edited on

let me put it to you in an easy language.
firstly you are declaring integer row with a value of 1.
and the condition is less than or equal to 9
then the incrementation ++row adds 1 to row.
then the looping begins
row comes with a value of 1 which is equal to col
so '*' is printed.
then then condition gets false.
and the same process continues!till the above condition
 (int row=1;row<=9;++row)
remains true!
Last edited on
yaraa wrote:
when I click run I get a black screen and then disappear

Yes, that happens when you run the "Hello World" program too. Here's some guidance:
Topic archived. No new replies allowed.