Friday, 5 April 2013

By Unknown   Posted at   Friday, April 05, 2013   No comments

PROGRAM TO CREATE DIFFERENT PATTERNS        .

#include<iostream.h>
#include<conio.h>
void pattern(char,int,int);
void main()
{ int nl,design;
  char ch;
  do{clrscr();
  cout<<"\n Enter the character: ";
  cin>>ch;
  cout<<"\n Enter the design type(1-5): ";
  cin>>design;
  cout<<"\n Enter the number of lines required: ";
  cin>>nl;
  pattern(ch,nl,design);
  getch();
  cout<<"\n Do you want to continue:(y/n) ";
  cin>>ch;
  }while(ch=='Y'||ch=='y');
}
void pattern(char a,int b,int c)
{ int i,j;
switch(c)
 {case 1: for(i=1;i<=b;++i)
     { for(j=1;j<=i;++j)
       cout<<a<<" ";
       cout<<"\n";
     }
     break;
  case 2: for(i=b;i>0;--i)
     { for(j=i-b;j>0;--j)
       cout<<" ";
       for(j=i;j>0;--j)
       cout<<a<<" ";
       cout<<"\n";
     }
     break;
  case 3: if(b%2==0)
     {  for(i=1;i<=b/2;++i)
     { for(j=1;j<=i;++j)
       cout<<a<<" ";
       cout<<"\n";
     }
     for(i=b/2;i>0;--i)
     { for(j=i-b/2;j>0;--j)
       cout<<" ";
       for(j=i;j>0;--j)
       cout<<a<<" ";
       cout<<"\n";
     }
     }
     else
     {  for(i=1;i<=b/2+1;++i)
     { for(j=1;j<=i;++j)
       cout<<a<<" ";
       cout<<"\n";
     }
     for(i=b/2;i>0;--i)
     { for(j=i-b/2;j>0;--j)
       cout<<" ";
       for(j=i;j>0;--j)
       cout<<a<<" ";
       cout<<"\n";
     }
     }
     break;
  case 4: for(i=1;i<=b;++i)
     { for(j=0;j<b-i;++j)
       cout<<" ";
       for(j=0;j<i;++j)
       cout<<a<<" ";
       cout<<"\n";
     }
     break;
  case 5: if(b%2==0)
    { for(i=1;i<=b/2;++i)
     { for(j=0;j<(b/2)-i;++j)
       cout<<" ";
       for(j=0;j<i;++j)
       cout<<a<<" ";
       cout<<"\n";
     }
      for(i=b/2;i>0;--i)
     { for(j=(b/2)-i;j>0;--j)
       cout<<" ";
       for(j=1;j<=i;++j)
       cout<<a<<" ";
       cout<<"\n";
     }
    }
      else
    { for(i=1;i<=b/2+1;++i)
     { for(j=0;j<((b/2)+1)-i;++j)
       cout<<" ";
       for(j=0;j<i;++j)
       cout<<a<<" ";
       cout<<"\n";
     }
      for(i=(b/2);i>0;--i)
     { cout<<" ";
       for(j=((b/2))-i;j>0;--j)
       cout<<" ";
       for(j=1;j<=i;++j)
       cout<<a<<" ";
       cout<<"\n";
     }
    }break;
 }
}

About the Author

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: BT9

0 comments :

Back to top ↑
Connect with Us

    Total Pageviews

    Powered by Blogger.

    Followers

    Blogroll

What they says

© 2013 The Programming Trailblazers . WP Mythemeshop Converted by Bloggertheme9
Blogger templates . Proudly Powered by Blogger .