Menu

Scripting Languages [ Lab Programs ]


multiplication tables

Aim:

  b) Write a Perl script to print the multiplication tables from 1-10 using subroutines.

Solution :

PROGRAM: (tables_print.pl)

 
#!/usr/bin/perl
use strict;
use warnings;

# Subroutine to print table of a number
sub print_table {
    my ($num) = @_;
    for my $i (1..10) {
        print "$num x $i = ", $num * $i, "\n";
    }
    print "\n";   
}

# Print tables from 1 to 10
for my $n (1..10) {
    print "Multiplication Table for $n:\n";
    print_table($n);
}


OUTPUT:

 
Multiplication Table for 1:
1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
1 x 4 = 4
1 x 5 = 5
1 x 6 = 6
1 x 7 = 7
1 x 8 = 8
1 x 9 = 9
1 x 10 = 10

Multiplication Table for 2:
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20

Multiplication Table for 3:
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30

Multiplication Table for 4:
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40

Multiplication Table for 5:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

Multiplication Table for 6:
6 x 1 = 6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
6 x 7 = 42
6 x 8 = 48
6 x 9 = 54
6 x 10 = 60

Multiplication Table for 7:
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70

Multiplication Table for 8:
8 x 1 = 8
8 x 2 = 16
8 x 3 = 24
8 x 4 = 32
8 x 5 = 40
8 x 6 = 48
8 x 7 = 56
8 x 8 = 64
8 x 9 = 72
8 x 10 = 80

Multiplication Table for 9:
9 x 1 = 9
9 x 2 = 18
9 x 3 = 27
9 x 4 = 36
9 x 5 = 45
9 x 6 = 54
9 x 7 = 63
9 x 8 = 72
9 x 9 = 81
9 x 10 = 90

Multiplication Table for 10:
10 x 1 = 10
10 x 2 = 20
10 x 3 = 30
10 x 4 = 40
10 x 5 = 50
10 x 6 = 60
10 x 7 = 70
10 x 8 = 80
10 x 9 = 90
10 x 10 = 100





Related Content :

1. Write a Ruby script to create a new string which is n copies of a given string where n is a non-negative integer.   View Solution


2. Write a Ruby script which accept the radius of a circle from the user and compute the perimeter and area.    View Solution


3. Write a Ruby script which accept the users first and last name and print them in reverse order with a space between them.   View Solution


4. Write a Ruby script to accept a filename from the user print the extension of that.   View Solution


5. Write a Ruby script to find the greatest of three numbers.   View Solution


6. Write a Ruby script to print odd numbers from 10 to 1.   View Solution


7. Write a Ruby script to check two integers and return true if one of them is 20 otherwise return their sum.   View Solution


8. Write a Ruby script to check two temperatures and return true if one is less than 0 and the other is greater than 100.   View Solution


9. Write a Ruby script to print the elements of a given array.   View Solution


10. Write a Ruby program to retrieve the total marks where subject name and marks of a student stored in a hash.   View Solution


11. Write a TCL script to find the factorial of a number.   View Solution


12. Write a TCL script that multiplies the numbers from 1 to 10.   View Solution


13. Write a TCL script for sorting a list using a comparison function.   View Solution


14. Write a TCL script to
(i) create a list
(ii) append elements to the list
(iii) Traverse the list
(iv) Concatenate the list    View Solution


15. Write a TCL script to comparing the file modified times.   View Solution


16. Write a TCL script to Copy a file and translate to native format.   View Solution


17. a) Write a Perl script to find the largest number among three numbers.   View Solution
      b) Write a Perl script to print the multiplication tables from 1-10 using subroutines.   View Solution


18. Write a Perl program to implement the following list of manipulating functions
a) Shift
b) Unshift
c) Push    View Solution


19. a) Write a Perl script to substitute a word, with another word in a string.   View Solution
      b) Write a Perl script to validate IP address and email address.   View Solution


20. Write a Perl script to print the file in reverse order using command line arguments.   View Solution