Square Pattern Of Numbers And Alphabets using CPP
- Home
- Tutorials
- CPP
- CPP Programs
- Pattern Programs
- Program
Source Code:
#include <iostream>
// standard namespace
using namespace std;
int main(int argc, char** argv) {
// maximum limt of rows
int max = 5;
// minimum limit of columns
int min = 1;
// printing square pattern
// outer loop
for (int i = min; i<=max; i++) {
// inner loop
for (int j = min; j<=max; j++) {
cout<<"* ";
}
cout<<endl; // move to new line/line change
}
return 0;
}
Output:
Working:
For pattern printing there is nested loop requirement. The outer loop is used to print lines and inner loop will print symbols or alphabets. In this program example we define to variables named as min and max for specifying minimum and maximum limits of the pattern. In nested loop we also declare counter variables.
In inner loop asterisk is displayed using cout statement. We can also print other symbol, chracter or number instead of asterisk.