Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
print_pattern_1.pl (#5580)
Browse files Browse the repository at this point in the history
Wrote a Perl program to print pattern 1 #3068

Co-authored-by: Harsh Raj <harshraj8843@gmail.com>
  • Loading branch information
pradeepch2107 and harshraj8843 authored Mar 28, 2024
1 parent 8e49f94 commit 6108413
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions program/program/print-diamond-pattern/print_pattern_1.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Perl program to print pattern 1

# Function to print pattern
sub print_pattern {
my $num = shift;

# Loop to iterate through each row
for my $i (1..$num) {
# Loop to print numbers in each row
for my $j (1..$i) {
print "$j ";
}
print "\n";
}
}

# Main program
print "Enter the number of rows: ";
my $input = <STDIN>;
chomp($input);

# Check if input is a positive integer
if ($input =~ /^\d+$/ && $input > 0) {
print_pattern($input);
} else {
print "Invalid input. Please enter a positive integer.\n";
}

0 comments on commit 6108413

Please sign in to comment.