Saturday 8 March 2014

C++ hollow diamond program


#include<iostream>
#include<conio.h>
using namespace std;

void main()
{
int Pheigt;
cout<<"Enter the height of paradigm:";
cin>>Pheigt;

int const margin_view = 20; //no need for constant it
int count;
int spaces_print;
int *ptr;

//**********************ROWS PRINT***************************************//
for(int i=0;i<=Pheigt;i++)
{

int spaces_to_print = margin_view +Pheigt - i; //*****************************//SETTING HOW MUCH SPACES TO PRINT

//cout<<spaces_to_print;
for(count = 0 ; count <= spaces_to_print; count++)
{
cout<<" ";
}

for(count = 0; count<=i*2; count++ ) //**********************PRINT STARS**************************//
{

if(count==0 || count==i*2)
{
cout<<"*";}
else{cout<<" ";}

}
ptr = &spaces_to_print;
//cout<<*ptr;
// cout<<spaces_to_print;
cout<<endl;
}

// cout<<*ptr;
int  margins_view = *ptr; //current spaces store to new variable

//*************************Row Loop***********************************************//
for(int i=Pheigt;i>=0;i--)
{
spaces_print = margins_view + Pheigt - i;
// cout<<spaces_print;

for(count = spaces_print ; count >=0; count --)
{

cout<<" ";
}

for(count=i*2;count>=0;count--)
{


if(count==0 || count==i*2)
{
cout<<"*";}
else{cout<<" ";}

//cout<<"*";
}

//spaces
cout<<endl;
}


_getch();
}


Enter the height of paradigm:7
                            *
                           * *
                          *   *
                         *     *
                        *       *
                       *         *
                      *           *
                     *             *
                     *             *
                      *           *
                       *         *
                        *       *
                         *     *
                          *   *
                           * *
                            *