Well, as you can see, all your inner loops come down to the same thing, they all have a start value (which even increments by one) and a check-value which is two times the start value.
The solution to this problem is:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <iostream>
using namespace std;
int main()
{
for(unsigned i=1;i<5;i++)
{
for(unsigned j=i;j<2*i;j++) cout << j;
cout << endl;
}
return 0;
}
|
I will try to explain why:
Rule 7: Loop for i from 1 to 5 (this is the problem mentioned at the first post)
Rule 9: Loop for j from i to 2*i and print j
Rule 10: After the second loop is executed, every character on this line is printed and we can continue on the next line, thus we send endl to cout
For example (rule 9):
In the first run, i = 1
j becomes 1 and goes from that to 2 (2*1), skipping 2. Thus, 1 is printed. Followed by an endl.
In the second run, i = 2
j becomes 2 and goes from that to 4 (2*2), skipping 4. Thus, 23 is printed. Followed by an endl.
In the third run, i = 3
j becomes 3 and goes from that to 6 (2*3), skipping 6. Thus, 345 is printed. Followed by an endl.
In the fourth run, i = 4
j becomes 4 and goes from that to 8 (2*4), skipping 8. Thus, 4567 is printed. Followed by an endl.
Then the loop ends since i is no longer underneath 5 (since i = 5).