Patterns Programs
Prepared by Prof. Anushree K. Rewale
* * * * * #include <iostream>
* * * * * using namespace std;
* * * * * int main() {
* * * * * int i,j;
* * * * *
for(i = 1; i <= 5; i++)
1 1 1 1 1 {
2 2 2 2 2 for(j = 1; j <= 5; j++)
3 3 3 3 3 {
4 4 4 4 4
cout<<" * "; //replace " * " with i & j variable
5 5 5 5 5
}
1 2 3 4 5 cout<<"\n";
1 2 3 4 5 }
1 2 3 4 5
return 0;
1 2 3 4 5
}
1 2 3 4 5 Prepared by Prof. Anushree K. Rewale
* #include <iostream>
* * using namespace std;
* * * int main() {
* * * * int i,j;
* * * * *
for(i = 1; i <= 5; i++)
1 {
2 2 for(j = 1; j <= i; j++)
3 3 3 {
4 4 4 4
cout<<“ * "; //replace " * " with i & j variable
5 5 5 5 5
}
1 cout<<"\n";
1 2 }
1 2 3
return 0;
1 2 3 4
}
1 2 3 4 5 Prepared by Prof. Anushree K. Rewale
* * * * * #include <iostream>
* * * * using namespace std;
* * * int main() {
* * int i,j;
*
for(i = 1; i <= 5; i++)
1 1 1 1 1 {
2 2 2 2 for(j = 5; j >= i; j--)
3 3 3 {
4 4
cout<<“ * "; //replace " * " with i & j variable
5
}
5 4 3 2 1 cout<<"\n";
5 4 3 2 }
5 4 3
return 0;
5 4
}
5 Prepared by Prof. Anushree K. Rewale
#include<iostream>
* using namespace std;
* * int main()
* * * {
int i, j, k;
* * * * for(i = 1; i <= 5; i++)
* * * * * {
/* Print spaces in decreasing order of row */
1 for(j = i; j < 5; j++)
{
2 2
cout<<" ";
3 3 3 }
4 4 4 4 /* Print star in increasing order or row */
5 5 5 5 5 for(k = 1; k <= i; k++)
{
cout<<"*"; //replace " * " with i & k variable
1 }
1 2 /* Move to next line */
1 2 3 cout<<"\n";
}
1 2 3 4 return 0;
1 2 3 4 5 } Prepared by Prof. Anushree K. Rewale
#include<iostream>
* * * * * using namespace std;
* * * * int main()
* * * {
int i, j, k;
* * for(i = 1; i <= 5; i++)
* {
/* Print spaces in increasing order of row */
1 1 1 1 1 for(j = 1; j < i; j++)
{
2 2 2 2
cout<<" ";
3 3 3 }
4 4 /* Print star in decreasing order or row */
5 for(k = 5; k >= i; k--)
{
cout<<"*"; //replace " * " with i & k variable
5 4 3 2 1 }
5 4 3 2 /* Move to next line */
5 4 3 cout<<"\n";
}
5 4 return 0;
5 } Prepared by Prof. Anushree K. Rewale
#include<iostream>
*
using namespace std;
* * * int main()
* * * * * {
* * * * * * * int i, j, k;
for(i = 1; i <= 5; i++)
* * * * * * * * * {
/* Print spaces in decreasing order of row */
1 for(j = i; j < 5; j++)
2 2 2 {
cout<<" ";
3 3 3 3 3 }
4 4 4 4 4 4 4 /* Print star in increasing order or row */
5 5 5 5 5 5 5 5 5 for(k = 1; k < (i*2); k++)
{
1 cout<<"*"; //replace " * " with i & k variable
}
1 2 3 /* Move to next line */
1 2 3 4 5 cout<<"\n";
1 2 3 4 5 6 7 }
return 0;
1 2 3 4 5 6 7 8 9 } Prepared by Prof. Anushree K. Rewale
* * * * * * * * * #include<iostream>
using namespace std;
* * * * * * * int main()
* * * * * {
* * * int i, j, k;
for(i = 5; i >= 1; i--)
* {
/* Print spaces in increasing order of row */
5 5 5 5 5 5 5 5 5 for(j = 5; j > i; j--)
4 4 4 4 4 4 4 {
cout<<" ";
3 3 3 3 3 }
2 2 2 /* Print star in decreasing order or row */
1 for(k = 1; k < (i*2); k++)
{
cout<<"*"; //replace " * " with i & k variable
1 2 3 4 5 6 7 8 9 }
1 2 3 4 5 6 7 /* Move to next line */
1 2 3 4 5 cout<<"\n";
}
1 2 3 return 0;
1 } Prepared by Prof. Anushree K. Rewale
* #include<iostream>
using namespace std;
* * int main()
* * * {
* * * * int i, j, k;
for(i = 1; i <= 5; i++)
* * * * *
{
for(j = i; j < 5; j++)
1 {
2 2 cout<<" ";
3 3 3 }
for(k = 1; k <= i; k++)
4 4 4 4 {
5 5 5 5 5 cout<<"*"; //replace " * " with i & k variable
cout<<" ";
1 }
1 2 cout<<"\n";
}
1 2 3 return 0;
1 2 3 4 }
1 2 3 4 5 Prepared by Prof. Anushree K. Rewale
* * * * * #include<iostream>
using namespace std;
* * * * int main()
* * * {
* * int i, j, k;
for(i = 1; i <= 5; i++)
*
{
for(j = 1; j < i; j++)
1 1 1 1 1 {
2 2 2 2 cout<<" ";
3 3 3 }
for(k = 5; k >= i; k--)
4 4 {
5 cout<<"*"; //replace " * " with i & k variable
cout<<" ";
5 4 3 2 1 }
5 4 3 2 cout<<"\n";
}
5 4 3 return 0;
5 4 }
5 Prepared by Prof. Anushree K. Rewale