Tag Archives: Pattern

Pyramid pattern

<br /> 

#include<iostream>
using namespace std;
int main()
{
int i,j,k,l,a;
cout<<"Enter the number of lines in the pyramid=";
cin>>a;
cout<<endl;
for(i=1;i<=a;i++)
{
for(j=a;j>=i;j--)
cout<<" ";
for(k=1;k<=i;k++)
{
cout<<"*";
}
for(l=1;l<=i-1;l++)
cout<<"*";

cout<<endl;

}
return 0;
}

 

output:

capture

Patterns

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;
}

pattern1
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;
}

pattern2

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;
}

pattern3

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;
}

pattern4
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;
}

pascal's triangle
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;
}

Floyd's triangle