Howdy, Stranger!

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

Categories

How to draw this shape with *'s

novabondnovabond Member Posts: 12
Hey, for an assignment I had to print out *'s in the shape like this:

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

The bad thing, now I have to print out something like this
(the O's are supposed to be blank spaces, because this
message board won't print it out the way it's supposed to :(

ooooo*
oooo**
ooo***
oo****
o*****
******

Could anyone send me a sample source code on how the heck to do that? I have tried numerous times, coming up with something wrong, and I've just given up. If anyone could do this, It'd be much appreciated :-) thanks a lot

[novabond]

Comments

  • ManningManning Member Posts: 1,621
    : ooooo*
    : oooo**
    : ooo***
    : oo****
    : o*****
    : ******
    :
    : Could anyone send me a sample source code on how the heck to do that? I have tried numerous times, coming up with something wrong, and I've just given up. If anyone could do this, It'd be much appreciated :-) thanks a lot

    First I would write a procedure to write a character a given number of times. Something simiple like:

    [code]
    procedure WriteCh(ACh: Char; ACount: Integer);
    var
    I: Integer;
    begin
    for I := 1 to ACount do
    Write(ACh);
    end;
    [/code]

    Then to actually draw the spaces and stars I would use a FOR loop with three lines inside. The first line would call WriteCh() to print the spaces, and the second line would call WriteCh() to print the stars (the third would be to advance the line of course).

    I dont want to give it away, so I wont include any code for the FOR loop, but a good hint would be to say that I would use the MOD operator to determine the number of spaces/stars to print. (If you dont know what MOD does, it returns the remainder of a division operation. So 5 MOD 2 would return 1 because 2 goes into 5 twice with 1 left over)
  • StarburnStarburn Member Posts: 17
    [b][red]This message was edited by Starburn at 2002-10-4 2:10:53[/red][/b][hr]
    Or if you were really lazy (I saw many people doing it in their first year of Computing).

    [code]
    Writeln(' *');
    Writeln(' **');
    [/code]

    and so on. (Thou you probably wouldnt get many marks for this, if its assessed :) ).
  • ThiagoThiago Member Posts: 4
    : Hey, for an assignment I had to print out *'s in the shape like this:
    :
    : *
    : **
    : ***
    : ****
    : *****
    : ******
    :
    : The bad thing, now I have to print out something like this
    : (the O's are supposed to be blank spaces, because this
    : message board won't print it out the way it's supposed to :(
    :
    : ooooo*
    : oooo**
    : ooo***
    : oo****
    : o*****
    : ******
    :
    : Could anyone send me a sample source code on how the heck to do that? I have tried numerous times, coming up with something wrong, and I've just given up. If anyone could do this, It'd be much appreciated :-) thanks a lot
    :
    : [novabond]
    :

    Hi,

    I'm a begginner too, so I made this code as an exercise. I think this could be of some help :




    Program FIXED_LENGTH;
    Uses Crt;

    var
    Long:integer;
    charact:char;
    ANS_YN:char;
    ANS:boolean;

    Procedure DRAW_SYMB(Length:integer;Character:char;Crescent:boolean);

    var
    AUX,COUNT,I:integer;

    Begin
    If Crescent then
    For Count:=1 to Length do
    Begin
    AUX:=Length-Count;
    For I:=1 to AUX do
    Write(' ');

    For I:=1 to Count do
    Write(character);

    Writeln;
    End
    Else
    For Count:=Length downto 1 do
    Begin
    AUX:=Length-Count;
    For I:=1 to AUX do
    Write(' ');
    For I:=1 to Count do
    Write(character);
    Writeln;
    End;
    End;


    Begin
    Writeln('How long will be the sequence ? ( in characters ) ... : ');
    Readln(Long);
    Writeln('What character do you want to use ? : ');
    Readln(charact);
    Writeln('Is the sequence crescent ? (Y/N) ... : ');
    Readln(ANS_YN);
    If ANS_YN='Y' then
    ANS:=True
    Else
    ANS:=False;
    DRAW_SYMB(Long,charact,ANS);
    ReadKey;
    End.






  • JoshellJoshell Member Posts: 3
    Greetings Novabond,

    I figure by now you have you problem solved, so I am posting a simple version of how I would do it. Also, I figure this thread is dead now, nobody is reading this probably, so what the heck.


    PROGRAM angle(OUTPUT);
    (* Reverse angle pattern *)

    VAR
    I, J, K: integer;

    BEGIN
    FOR I := 1 TO 5 DO
    BEGIN
    FOR J := 4 DOWNTO I DO
    write(' ');
    FOR K := 1 TO I DO
    write('*');
    writeln;
    END
    END.


    Here is a alternate version of Thiago's program.


    PROGRAM angle2(INPUT, OUTPUT);
    (* Variable reverse angle pattern *)

    VAR
    C: CHAR;
    I, J, K, N: INTEGER;

    BEGIN
    write('How many? ');
    readln(N);
    write('What Character? ');
    readln(C);
    writeln;
    FOR I := 1 TO N DO
    BEGIN
    FOR J := N - 1 DOWNTO I DO
    write(' ');
    FOR K := 1 TO I DO
    write(C);
    writeln;
    END
    END.
  • Shawn CarterShawn Carter Member Posts: 0

    _ // http://forcoder.org // free video tutorials and ebooks about ( Assembly JavaScript Visual Basic Delphi C MATLAB Objective-C Python Scratch Java PHP Visual Basic .NET Ruby C++ C# R Perl Swift Go PL/SQL Julia Ada Bash VBScript Lua FoxPro Fortran Kotlin F# Awk LabVIEW Hack Clojure Lisp Logo Prolog SAS Rust Crystal ML Dart Apex D COBOL Scheme Transact-SQL Erlang ABAP Scala Alice ) _____________

Sign In or Register to comment.