Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

having a hard time trying to create a perl program that ulilizes two inputs and

ID: 3828067 • Letter: H

Question

having a hard time trying to create a perl program that ulilizes two inputs and puts them in three different patterns.

Write a Perl script to do the following Make sure you loo Just hardcoding lines will receive only 50% of the grade. First, prompt for the following: Maximum number of characters in a line 6 Enter Echo Character Print the following patterns with the title as shown on the left hand side. Pattern 1: Pattern 2: 12 123 1234 12345 123456 Pattern 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Note: Input number 6 above is just an example. If you enter a number n, then all patterns MUST print n number of lines. The echo character you input is applicable only to pattern 1.

Explanation / Answer

print "Maximum number of characters in a line: ";

my $lines = <STDIN>;

print "Enter Echo Charcter: " ;
my $char = <STDIN>;
chomp($char);

my $i;

for ($i = $lines; $i > 0; $i = $i -1)
{
my $j;
for($j = 0; $j < $i; $j = $j +1)
{
print "$char";
}
print " ";
}

for ($i = 0; $i < $lines; $i = $i+1)
{
my $j;
for($j = 1; $j <= $i +1; $j = $j +1)
{
print "$j";
}
print " ";   
}

$k = 1;

for ($i = 0; $i < $lines; $i = $i+1)
{
my $j;
for($j = 1; $j <= $i +1; $j = $j +1)
{
print "$k ";
$k = $k +1;
}
print " ";
}

Sample run

Maximum number of characters in a line: 6
Enter Echo Charcter: $
$$$$$$
$$$$$
$$$$
$$$
$$
$
1
12
123
1234
12345
123456
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21