How to make pyramid Numbers & Stars in Pascal ? - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# How to make pyramid Numbers & Stars in Pascal ?

Posts: 3Member
Like this One..

• Posts: 31Member
Good day well what you need to do is run a for within a for... the First of which will obivious run the full length u need and the other only to the current position....

It should look like this...

Now before we start there is a few things we need to take into consideration...

eventually we want it tolook like
*
*1*
*121*
*12321*
*1234321*
*123454321*
*12345654321*
*1234567654321*
*123456787654321*
*****************
and everthing else must be centred ontop if it and that is the tricky part. This caused all the lines to be of odd lengths

Program pyramid;
Uses Crt;

Var
J,K,N,M : Integer;
{J will be our counter for each line}
{K will be our counter for each character per line}
{N will be out goal number of lines}
{M will be used to centre everything}
str1 : string;

Begin
Writeln('How many lines must the pyramid be: ');

Writeln;
M := (N);
Writeln('*'m); {This places our first star at the top in the middle}
For J := 1 to N-1 do {This is the pyramid}
Begin
Write('*'m-J); {creates the leading "*",also positioning us at the correct spot}
For K := 1 to J do {Fills the line with 123...}
Begin
Write(k);
End;
For K := J-1 downto 1 do {Completes the line with ...321, note becus the first line will be from 0 downto 1 nothing will happen}
Begin
Write(k);
End;

Write('*'); {Creates the trailing "*"}
Writeln; {Takes us to the next line}
End;
For K := 1 to N do {Makes the last line only stars the amount as entered at the start}
Begin
Write('*');
End;

Writeln;
Writeln('Press any key to exit program');
End;

Hope this help u out

Darkwing Duck aka DWduck signing off
• Posts: 31Member
Good day well what you need to do is run a for within a for... the First of which will obivious run the full length u need and the other only to the current position....

It should look like this...

Now before we start there is a few things we need to take into consideration...

eventually we want it tolook like
*
*1*
*121*
*12321*
*1234321*
*123454321*
*12345654321*
*1234567654321*
*123456787654321*
*****************
and everthing else must be centred ontop if it and that is the tricky part. This caused all the lines to be of odd lengths

Program pyramid;
Uses Crt;

Var
J,K,N,M : Integer;
{J will be our counter for each line}
{K will be our counter for each character per line}
{N will be out goal number of lines}
{M will be used to centre everything}
str1 : string;

Begin
Writeln('How many lines must the pyramid be: ');

Writeln;
M := (N);
Writeln('*'m); {This places our first star at the top in the middle}
For J := 1 to N-1 do {This is the pyramid}
Begin
Write('*'m-J); {creates the leading "*",also positioning us at the correct spot}
For K := 1 to J do {Fills the line with 123...}
Begin
Write(k);
End;
For K := J-1 downto 1 do {Completes the line with ...321, note becus the first line will be from 0 downto 1 nothing will happen}
Begin
Write(k);
End;

Write('*'); {Creates the trailing "*"}
Writeln; {Takes us to the next line}
End;
For K := 1 to N do {Makes the last line only stars the amount as entered at the start}
Begin
Write('*');
End;

Writeln;
Writeln('Press any key to exit program');
End;

Hope this help u out

Darkwing Duck aka DWduck signing off
• Posts: 31Member
Good day well what you need to do is run a for within a for... the First of which will obivious run the full length u need and the other only to the current position....

It should look like this...

Now before we start there is a few things we need to take into consideration...

eventually we want it tolook like
*
*1*
*121*
*12321*
*1234321*
*123454321*
*12345654321*
*1234567654321*
*123456787654321*
*****************
and everthing else must be centred ontop if it and that is the tricky part. This caused all the lines to be of odd lengths

Program pyramid;
Uses Crt;

Var
J,K,N,M : Integer;
{J will be our counter for each line}
{K will be our counter for each character per line}
{N will be out goal number of lines}
{M will be used to centre everything}
str1 : string;

Begin
Writeln('How many lines must the pyramid be: ');

Writeln;
M := (N);
Writeln('*'m); {This places our first star at the top in the middle}
For J := 1 to N-1 do {This is the pyramid}
Begin
Write('*'m-J); {creates the leading "*",also positioning us at the correct spot}
For K := 1 to J do {Fills the line with 123...}
Begin
Write(k);
End;
For K := J-1 downto 1 do {Completes the line with ...321, note becus the first line will be from 0 downto 1 nothing will happen}
Begin
Write(k);
End;

Write('*'); {Creates the trailing "*"}
Writeln; {Takes us to the next line}
End;
For K := 1 to N do {Makes the last line only stars the amount as entered at the start}
Begin
Write('*');
End;

Writeln;
Writeln('Press any key to exit program');