Posts which you will also like.

Saturday, August 14, 2010

Print Diamond of Astrik (A C++ program)

This is a generic function to print Diamond.
Simply pass the argument n as needed by you and call the function as and when needed.
Happy programming..
void print(int n)
{    int j,k,sp=18;
     for(int i=1;i
             {          for(k=1;k<=sp;k++)
                        {
                         cout<<" ";
                       
                         } sp-=2;
                        
                         for(j=1;j<=2*i-1;j++)
                         {
                                 cout<<"* ";
                          }
                          cout<<"\n";
             }
            
             sp+=2;
             for(int i=n-1;i>0;i--)
                     {    sp+=2;
                         for(int l=1;l<=sp;l++)
                         { cout<<" ";
                         }
                       
                         for(int j=2;j<2*i-1;j++)
                         {
                                 cout<<"* ";
                         }
                         cout<<"\n";
                     }

}
OutPut:
                                       
             *
           ***
          *****
        *******
          *****
           ***
             *

 

No comments:

Post a Comment

Your comment may wait for moderation....

DMCA.com Protected by Copyscape Online Plagiarism Tool