Need help on this problem please.

What will this C++ code output?
Having some trouble on this problem, what is the output for this code (Assuming its part of a working program, assuming proper headers and whatnot)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
for (int i = 0; i < 5; i++) 

{ 

for (int j = 0; j <= i; j++) 

{ 

cout << "*"; 

} 

cout << endl; 

}
Run it.
since you're starting at i = 0 and going as long as i is <5, there will be five lines. On each of these lines, i decides how many * there will be, because the loop with j will only print * as long as j is <= i. So the the first loop through of i, i = 0, and the first loop through of j, j=0. Since j is <= i, an * will be printed and j++. The j loop will not run again because j now equals 1 which is not <= i. The line is ended and the second loop of i is begun. This continues until i<5 is no longer true.
Registered users can post here. Sign in or register to post.