Perl script to print half daimond star pattern

GOCOURSE

Print half daimond star pattern

Program:

 #!/usr/bin/perl

use strict;
use warnings;

my $size = 5;

for (my $i = 1; $i <= $size; $i++) {
    for (my $j = 1; $j <= $i; $j++) {
        print("*");
    }
    print("\n");
}

for (my $i = $size - 1; $i >= 1; $i--) {
    for (my $j = 1; $j <= $i; $j++) {
        print("*");
    }
    print("\n");
}

Output:

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

Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send