Number Pattern
Program to print number pattern
BeginnerTopic: Pattern Programs
C++ Number Pattern Program
This program helps you to learn the fundamental structure and syntax of C++ programming.
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Enter number of rows: ";
cin >> rows;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
cout << j << " ";
}
cout << endl;
}
return 0;
}Output
Enter number of rows: 5 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
Understanding Number Pattern
This pattern prints numbers instead of stars. In row i, we print numbers from 1 to i. The inner loop variable j is printed, creating a sequence that increases with each row.
Note: To write and run C++ programs, you need to set up the local environment on your computer. Refer to the complete article Setting up C++ Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your C++ programs.