Posts which you will also like.

Tuesday, August 17, 2010

A Diamond Series(similar to pascal triangle)





A C++ Program to print the following diamond Series:

                          1
                       2 3 2
                    3 4 5 4 3
                 4 5 6 7 6 5 4
              5 6 7 8 9  8 7 6 5
                 4 5 6 7 6 5 4
                    3 4 5 4 3
                       2 3 2
                          1
------------------------------------------------------------------------------------------------------------
#include
#include
void print(int n)
{
     int k=1,l,s=0,sp=20;
     for(int i=1;i<=n;i++)
     {       l=k;
             for(int p=0;p<=sp;p++)
             {
                     cout<<" ";
             }
             for(int j=1;j<=i;j++)
             {
                     cout<<(l%10)<<" ";
                     l++;
             }
            k++;
            sp=sp-2; 
                    if(k>2)
                    {      s=s+2;
                           int m=s;
                           cout<<(s%10)<<" ";
                           while(m>=k)
                           { m--;
                             cout<<(m%10)<<" ";
                           
                            }
                                         
                              
                   
                    }    cout<<"\n";
            }
            k-=1;
            sp=sp+2;
     for(int i=n-1;i>=1;i--)
     {       sp=sp+2;
             for(int p=0;p<=sp;p++)
             {
                     cout<<" ";
             }
           l=--k;
           int f;
             for(int j=1;j<=i;j++)
             {
                     cout<<(l%10)<<" ";
                     f=l;
                     l++;
                  
             }
             for(int j=1;j
             {        f--;
                     cout<<(f%10)<<" ";
                   
             }
             cout<<"\n";    
     }

}

int main()
{
     print(6); //pass parameter n as your wish
     system("pause");
     return 0;
}
Read More ->>

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:
                                       
             *
           ***
          *****
        *******
          *****
           ***
             *

 
Read More ->>

Friday, August 6, 2010

Get The Complete Reference Of Dos Commands

For A-Z reference about Dos Commands:
Start Run prompt and type following:
1. %windir%\hh.exe ms-its
2.or %windir%\Help\ntcmds.chm::/ntcmds.htm
It contains everything you need to know about Dos Commands......
Read More ->>
DMCA.com Protected by Copyscape Online Plagiarism Tool