Printing characters pattern using the nested for loop C++ code sample

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: To print characters pattern using the nested for loop in C++ programming

To show: How to print a pattern of characters using the nested for loop in C++ programming

 

 

// program to show the nested for loop C++ example

#include <iostream>

using namespace std;

 

int main(void)

{

// variables for counter

int i, j;

 

// outer loop, execute this first

for(i=1; i<11; i++)

{

cout<<"\n"<<i;

// then execute inner loop with loop index j

// the initial value of j is i + 1

for(j=i+1; j<11; j++)

// Display result...

cout<<j;

// increment the counter by 1 for inner loop

}

// increment the counter by 1 for outer loop

cout<<"\n";

 

return 0;

}

 

Output example:

 

12345678910

2345678910

345678910

45678910

5678910

678910

78910

8910

910

10

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index