Pattern 1:
/* * * * * * * * * * * * * * * * */ #include <iostream> using namespace std; int main() { int i,j,rows; cout<<"Enter the number of rows: "; cin>>rows; for(i=1;i<=rows;++i) { for(j=1;j<=i;++j) { cout<<"* "; } cout<<"n"; } return 0; }
Pattern 2:-
<br />/* 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 */ #include <iostream> using namespace std; int main() { int i,j,rows; cout<<"Enter the number of rows: "; cin>>rows; for(i=1;i<=rows;++i) { for(j=1;j<=i;++j) { cout<<j<<" "; } cout<<"n"; } return 0; }
Pattern 3:-
/* * * * * * * * * * * * * * * * */ #include <iostream> using namespace std; int main() { int i,j,rows; cout<<"Enter the number of rows: "; cin>>rows; for(i=rows;i>=1;--i) { for(j=1;j<=i;++j) { cout<<"* "; } cout<<"n"; } return 0; }
Pattern 4:-
/* 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 */ #include <iostream> using namespace std; int main() { int i,j,rows; cout<<"Enter the number of rows: "; cin>>rows; for(i=rows;i>=1;--i) { for(j=1;j<=i;++j) { cout<<j<<" "; } cout<<"n"; } return 0; }
Pattern 5:-(Pascal’s Triangle)
<br />#include<iostream> using namespace std; int main() { int rows; cout << "Enter the number of rows : "; cin >> rows; cout << endl; for (int i = 0; i < rows; i++) { int value = 1; for (int j = 1; j < (rows - i); j++) { cout << " "; } for (int k = 0; k <= i; k++) { cout << " " << value; value = value * (i - k) / (k + 1); } cout << endl << endl; } cout << endl; return 0; }
Pattern 6:-
(floyd’s Triangle)
#include <iostream> using namespace std; int main() { int rows,i,j,k=1; cout<<"Enter number of rows: "; cin>>rows; for(i=1;i<=rows;i++) { for(j=1;j<=i;j++) cout<<k++<<" "; cout<<endl; } return 0; }