develooper Front page | perl.beginners | Postings from February 2002

Help can't figure this one out

Thread Next
From:
Bruce Ambraal
Date:
February 13, 2002 22:25
Subject:
Help can't figure this one out
Message ID:
sc6b7432.099@cct.org.za
I have written following coding to produce a triangle pattern(see below);
I now want to  produce following paterns I can't figer this out

        (a)            (b)                 (c)                 (d) diamond                            
           *            * * * * *           * * * * *          *
         * *           * * * *                * * * *        * * *
       * * *           * * *                    * * *       * * * *
     * * * *           * *                        * *      * * * * *
   * * * * *          *                             *        * * * *
                                                                * * *
                                                                  *
______________________________________________             
#!/usr/local/bin/perl -w
my $num_rows;
my $i;
my $r;

$num_rows = <STDIN>;

for ($r = 1; $r <= $num_rows; $r++)
    {
    # indent by printing num_rows - r spaces
    for ($i = 1; $i <= $num_rows - $r; $i++) {print ("  \n");}
    # print r asterisks
       for ($i=1; $i<= $r; $i++) { print ("     *");}
    # drop cursor to a new line
      print "\n";
     }
# end for

-------------------------------------
unxsup:/home/bruce$ perl triangle.pl
5




     *



     *     *


     *     *     *

     *     *     *     *
     *     *     *     *     *

Cheer
Bruce


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About