Need help with Perl, using perl 5 Problem A10 Write a program that reads in thre
ID: 3600770 • Letter: N
Question
Need help with Perl, using perl 5
Problem A10
Write a program that reads in three numbers:
Ask the user to input a decimal number as the first number.
Ask the user to input an octal number without the leading 0 as the second number.
Ask the user to input a hexadecimal number without the leading 0X as the third number.
Convert each number to decimal.
Print the following output, with description of each number:
Print the decimal value of the first number.
Print the octal and then the decimal value of the second number.
Print the hexadecimal and then the decimal value of the third number.
Use the following test data, in order: 1234 123 12
Explanation / Answer
Ans.)
Please find the perl script below :
print "Input a decimal number? ";
$first = <>;
printf($first);
print "Input an octal number without the leading 0? ";
$second = <>;
printf($second);
print "Input a hexadecimal number without the leading 0X? ";
$third = <>;
printf($third);
printf("The decimal value of $first is %i ",$first);
printf("The octal value of $second is $second and the decimal value of $second is %i ",oct $second);
printf("The hexadecimal value of $third is $third and the decimal value of $third is %i ",hex $third);
STDIN :
1234
123
12
Output :
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.