Pattern Programs
Pattern is nothing but series of any character either it is series of number or any characters that are used to create some pattern or geometrical shape.
Pattern programs are one of the test practicable programs which increases our efficiency to code for graphics patterns.
Pattern programs enhance your logical thinking abilities by coding.Below is a list of basic pattern programs which will be useful for you.
1.Write a program to print the following patterns.
****
***
**
*
#include<iostream.h> #include<conio.h> #define MAXSIZE 100 void main() { int n,i=0,j=0; clrscr(); cout<<"\n How many rows you want in this pattern \n"; cin>>n; cout<<"\n"; for (i = 0; i < n; i++) { for (j = n; j > i; j--) { cout<<"*"; } cout<<"\n"; } getch(); }
2.Write a program to print the following patterns.
*
**
***
****
#include<iostream.h> #include<conio.h> void main() { int n,i=0,j=0,k=0; clrscr(); cout<<"\n How many rows you want in this pattern \n"; cin>>n; cout<<"\n"; for (i = 0; i < n; i++) { for (j = n - 1; j > i; j--) { cout<<" "; } for (k = 0; k <= i; k++) { cout<<"*"; } cout<<"\n"; } getch(); }
3.Write a program to print the following patterns.
#include<iostream.h> #include<conio.h> void main() { int n,i=0,j=0,k=0,count=1; clrscr(); cout<<"\n How many rows you want in this pattern \n"; cin>>n; cout<<"\n"; for (i = 0; i < n; i++) { for (j = n - 1; j > i; j--) { cout<<" "; } for (k = 0; k < count; k++) { cout<<"*"; } count = count + 2; cout<<"\n"; } getch(); }
4.Write a program to print the following patterns.
#include<iostream.h> #include<conio.h> void main() { int n,i=0,j=0,k=0; clrscr(); cout<<"\n How many rows you want in this pattern \n"; cin>>n; cout<<"\n"; for (i = 0; i < n; i++) { for (j = 0; j < i; j++) { cout<<" "; } for (k = n; k > i; k--) { cout<<"*"; } cout<<"\n"; } getch(); }
5.Write a program to print the following patterns.
#include<iostream.h> #include<conio.h> void main () { int n,i=0,j=0; clrscr(); cout<<"\n How many rows you want in this pattern \n"; cin>>n; cout<<"\n"; for (i = 0; i < n; i++) { for (j = 0; j <= i; j++) { cout<<"*"; } cout<<"\n"; } getch(); }