This is the Question:-

3)Implement oon pascal a program to produce the following output:-

*
**
***
****
*****

The number of rows to be printed on the screen should be specified buy the user nad you have to use for loops.


i have done the bit where it just outputs:-
*
**
***
****
*****
but the bit i can do is for the user to specify the number of lines there are?

this is my programming language for the bit i have done:-

Program Question_3;
Uses Wincrt;

Var
   x   :   integer;

Begin

 For x:= 1 to 1 do
    Begin
     write('*')
    End;
    writeln;

 For x:= 1 to 2 do
    Begin
     write('*')
    End;
    writeln;

 For x:= 1 to 3 do
    Begin
     write('*')
    End;
    writeln;

 For x:= 1 to 4 do
    Begin
     write('*')
    End;
    writeln;

 For x:= 1 to 5 do
    Begin
     write('*')
    End;
    writeln;

End.

Any time you find that you are repeating yourself, that is a good thing to turn into a loop.

First, figure out what changes each time and what stays the same. The thing that changes is a variable.
In your examples (done with [[I][/I]inlinecode[I][/I]] so that I can highlight something) they are all the same except for one thing: For x:= 1 to [B]1[/B] do Begin write('*') End; writeln; The only thing that changes each time is the number of times you go through the for loop. The first time it is 1, the second time it is 2, the third time it is 3, etc. Fortunately, you can use a for loop to count numbers 1, 2, 3, etc. (It is OK to have a loop inside another loop.)

That should be enough to help. Good luck.

This article has been dead for over six months. Start a new discussion instead.