programming-examples/perl/Basics/Use parentheses wherever possible to force precedence.pl

23 lines
591 B
Perl
Raw Normal View History

2019-11-18 14:44:36 +01:00
#!/usr/local/bin/perl -w
print "Enter the first number : ";
my $num1 = <STDIN>; chomp $num1;
print "Enter the second number: ";
my $num2 = <STDIN>; chomp $num2;
print "Enter the third number : ";
my $num3 = <STDIN>; chomp $num3;
# A*B-C
my $answer = $num1 * $num2 - $num3;
print "$num1 * $num2 - $num3 = $answer \n";
# (A*B)-C
$answer = ($num1 * $num2) - $num3;
print "($num1 * $num2) - $num3 = $answer \n";
# A*(B-C)
$answer = $num1 * ($num2 - $num3);
print "$num1 * ($num2 - $num3) = $answer \n";