Monday, 9 January 2017

Write a Perl script that prints the numbers from 1 to 100, but for multiples of three print “Fast” instead of the number and for the multiples of seven print “Car”. For the numbers which are multiples of both three and seven print “FastCar”.

use warnings;
use strict;
my  $l=1;
for($l=1;$l<=100;$l++)
{
if( $l % 3 == 0 && $l % 7 == 0 ) {
                print "FastCar";
                print"\n";
               
              }
             elsif( $l % 3 == 0 && $l % 7 != 0 ) {
                    print "Fast";
                    print "\n";
                   
             }
             elsif( $l % 3 != 0 && $l % 7 == 0 ) {
                    print "Car";
                    print"\n";
                   
             }
             else {
                print $l;
                print "\n";
               
             }
}

No comments:

Post a Comment