Category 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

Christmas Tree

Christmas tree

<br />#include<iostream>
using namespace std;
int main()
{
cout<<"tt -:Christmas Tree:-"<<endl;
int a=15,x,b,p=0;
for(b=1; b<=a; b++)
{
p++;
for(int i=0;i<=p;i++)
{
for(x=2*a-1-i;x>=b;x--)
{
cout<<" ";
}
if(b+i<a)
{
for(int x=1;x<=b+i;x++)

{
cout<<"* ";
}
cout<<endl;
}
else
goto end;
}
}
end:
p=0;
for(int i=0;i<6;i++)
{
for(int j=12+p;j>=1;j--)
{
cout<<" ";
}
p=a;
for(int k=0;k<3;k++)
{
cout<<"* ";
}
cout<<endl;
}
cout<<"ttttt@ Myprogworld.....!!"<<endl;
}

Star Pattern

star pattern

<br />#include<conio.h>
#include<iostream>
#include<windows.h>
#include<time.h>
using namespace std;
void gotoxy (int x, int y)
{
COORD coord;
coord.X = x; coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int main()
{
start:
char ch;
float k=0;
cout<<"tttt-:star Pattern:-";
gotoxy(40,1);
cout<<"*";
for(int i=0;i<=5;i++)
{
gotoxy(40-i,i+1);
cout<<"*";
gotoxy(40+i,i+1);
cout<<"*";
Sleep(100);
}
for(int j=0;j<=5;j++)
{
gotoxy(45+j,6);
cout<<"*";
gotoxy(35-j,6);
cout<<"*";
Sleep(100);
}
for(int i=0;i<=5;i++)
{
gotoxy(52-i,6+i);
cout<<"*";
gotoxy(28+i,6+i);
cout<<"*";
Sleep(100);
}
for(int i=0;i<=5;i++)
{
gotoxy(47+i,11+i);
cout<<"*";
gotoxy(33-i,11+i);
cout<<"*";
Sleep(100);
}
for(int i=0;i<=5;i++)
{
gotoxy(52-k,17-i);
cout<<"*";
gotoxy(28+k,17-i);
cout<<"*";
k=k+2.4;
Sleep(100);
}
gotoxy(38,18);
cout<<"(-_-)";
gotoxy(26,20);
cout<<"Once Again...!!!!Press{ <---' }";
ch=getch();
if(ch==13)
{
system("cls");
goto start;
}
else
getch();
return 0;
}