Nested for loop help

This code is killing me. I want to write a code that outputs

1
2 3
3 4 5
4 5 6 7
5 6 7 8 9
6 7 8 9 10 11

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# include <iostream >

using namespace std;

int main()

{
    int  row;
    int  col;
    int col2;
   
   
    
    for (row=1 ; row <7 ; row++)
    {
      cout <<  row <<endl;
    
       for(col= 0;col <= row; col++)
            {
                  
               
                  for(col2=1; col2 < row; col2++)
 {
                  
                  }
                
                  
                   cout << col2 << " "; 
                  }
 
                
}
    
                   
                               
    system ("pause");
    return 0;
}   
                          
   


I have changed this around so that it can increment the rows but not the columns but then I can't get the first line to change. This is driving me crazy. Not in school BTW just trying to teach myself how to code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

int main()
{
    const int NUM_ROWS = 6 ;
    
    for( int row = 1 ; row <= NUM_ROWS ; ++row ) // for each row 1 .. NUM_ROWS
    {
        // print numbers row, row+1 ... (row times) 
        for( int col = 0 ; col < row ; ++col )
        {
            std::cout << row+col << ' ' ;
        }
        
        std::cout << '\n' ; // and a new line at the end of each row
    }
}

http://coliru.stacked-crooked.com/a/e84641c5947df649
Dang, you beat me to it. Here's what I came up with. It's slightly different.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main ( )
{
	int count; // the number of numbers to print
	
	const int rows = 6; // the number of rows to print
	
	int num; // the number to print


	for ( count = 1; count <= rows; ++count )
	{
		num = count;

		for ( int i = 0; i < count; ++i )
		{
			std::cout << num++ << ' ';
		}

		std::cout << '\n';
	}
}
Try this loop.I dont have laptop or PC so i havent compiled. but i guess it should work.
1
2
3
4
5
6
7
8
9
int i,j,k;
for(i=1;i<=5;i++)
{
k=i;
for(j=1;j<=i;j++)
{
cout<<k++;
}
}
Topic archived. No new replies allowed.