Lab04 (Pattern) NEW

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

#include <iostream>

using namespace std;


void main()
{
for (int h=0 ;h<5;h++)
{
for(int m=0;m<4-h;m++)
{
cout<<" ";
}
for(int s=0;s<(2*h)+1;s++)
{
cout<<"*";
}
cout<<endl;
}
//-------------------------------------------
for (int h=0 ;h<4;h++)
{
for(int m=0;m<1+h;m++)
{
cout<<" ";
}
for(int s=0;s<7-(h*2);s++)
{
cout<<"*";
}
cout<<endl;
}
system ("pause");
}

#include<iostream>
using namespace std;
void main()
{
int n, s, i, j;
cout << "Enter number of rows: ";
cin >> n;
for(i = 0; i <= n; i++)
{
for(s = n; s > i; s--)
cout << " ";
for(j=0; j<i; j++)
cout << "* ";
cout << "\n";
}
//------------------------------
for(i = 1; i < n; i++)
{
for(s = 0; s < i; s++)
cout << " ";
for(j = n; j > i; j--)
cout << "* ";
cout << "\n";
}
system("pause");
}

#include<iostream>
using namespace std;
void main()
{
int n, i , j;
cout << "Enter number of rows: ";
cin >> n;
for(i = 1; i <= n; i++)
{
for(j = 1; j <= i; j++)
{
cout << "*";
}
cout<<"\n";
}

for(i = n; i >= 1; i--)


{
for(j = 1; j <= i; j++)
{
cout << "*" ;
}
cout<<"\n";
}
system ("pause");
}

#include <iostream>
#include <iostream>
using namespace std;
using namespace std;
void main() {
void main() {

for (int i = 1; i <= 5; i++) for (int i = 0; i < 5; i++)


{ {
for (int j = 5; j > i; j--)
cout << " "; 4
for (int j = 0; j < -i ; j++)
for (int k = 0; k < i * 2 - 1; k++) cout << " ";
{ for (int k = 0; k < (i*2)+1 ; k++)
if (k == 0 || k == 2 * i - 2) cout << "*"; {
else cout << " "; if (k == 0 || k == (i*2)) cout <<
} "*";
cout << "\n"; else cout << "
} ";
// ------------------------------------------- }
for (int i = 1; i < 5; i++) cout << "\n";
{ }
for (int j = 0; j < i; j++) //
cout << " "; -------------------------------------------
for (int k = (5 - i) * 2 - 1; k >= 1; k--)
{
4
for (int i = 0; i < ; i++)
if (k == 1 || k == (5 - i) * 2 - 1) cout << "*"; {
else cout << " "; for (int j = 0; j < i+1 ; j++)
} cout << " ";
cout << "\n"; 7
for (int k = 0; k < ( -(i*2)) ; k++)
} {
6
if (k == 0 || k == ( -(i*2))) cout <<
"*";
else cout <<
" ";
}
cout << "\n";
system ("pause");
}#include <iostream>
using namespace std;

void main() {
int r;
cout << "Enter number of rows: ";
cin>>r;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < r-1-i ; j++)
cout << " ";
for (int k = 0; k < (i*2)+1 ; k++)
{
if (k == 0 || k == (i*2)) cout << "*";
else cout << " ";
}
cout << "\n";
}
//-------------------------------------------
for (int i = 0; i < r-1; i++)
{
for (int j = 0; j < i+1 ; j++)
cout << " ";
for (int k = 0; k < ((r+(r-3))-(2*i)) ; k++)
{
if (k == 0 || k == ((r+(r-3))-(2*i))-1) cout << "*";
else cout << " ";
}
cout << "\n";
}

system ("pause");
}

You might also like