Thursday 6 March 2014

C++ FULL PARAMID PROGRAM EASIEST APPROACH

QUESTIONS IN MIND

How much height you want to draw paramid?

Want to draw in Center of screen to show beauty?
if you dont pass spaces loop what happens?
why Nested Loop is important in this program?


Many questions are produced in mind of new programmers I have solution

height is set because program does not know what to draw you have to pass the height of pyramid that program can knew that height is etc height = 10; then it has to use logical height 10 times.

why nested loop ?
Always Remember C++ compiler only draw in form of rows and column a loop

nested means loop under a loop
ROW(PROGRAMMING){
_________COL(PROGRAMMING)
}

first loop is for rows (------------------------------)to print

 2nd loop is for the column to print
(
|
|
|
)


now how to draw pyramid??
Usually most of the time teachers and colleagues don't tell you what is logic to print it in easy way, i am experienced  person so i will help you guys

1)ROWS
first of all you have to print pass the loop to compiler C++ which starts from 0 and ends to height you know
in which it now needs to know in a line single or line by line
you have to use \n or endl to print row by row a (loop prints row)


2) COLUMNS

As you see pyramid
                            *
                          ***
                         *****

you notices their are spaces and margin in center and printing '*' in both sides

how
you have to define integer variable to set margin = for example 10
know

you have to store spaces for rows you see spaces are row by row reduced to help static print at left

int spaces = margin_you have given + height you have give -  rows loop current value
your spaces for current loop row will be set

you have to print spaces for this row
until this row spaces value reached
_______________________________

you above see line it shows space of current row


Now you have to print *
use a loop goes to current row*2 value of loop and print *
initally 0 then one star will be print
now
you se
_______________________________*

loop continues
row incremented
colomn space decremented
stars in row incremented

___________________________*
__________________________***
_________________________*****
________________________*******
_______________________*********
______________________***********
till height is given


//CODE

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

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

int margin_view = 20; //no need for constant it
int count;


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

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


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

for(count = 0; count<=i*2; count++ ) //**********************PRINT STARS**************************//
{
cout<<"*";
}
// cout<<spaces_to_print;
cout<<endl;
}

_getch();
}