Write a Perl program that allows the user to input a 5-digit nonnegative integer
ID: 3743775 • Letter: W
Question
Write a Perl program that allows the user to input a 5-digit nonnegative integer number between 10000 and 99999 , separates that number into its individual digits and then prints the digits to the screen separated from one another by three spaces each.
Requirement: 1.Do not use loops, arrays or the split or substr functions for this.
2.Use the smart-match operator, relational operators, if conditional statements, the given statement and Boolean logical operators.
Sample Run1:
Enter a five-digit number: 68182
6 8 1 8 2
2:Enter a five-digit number: 1234
ERROR: Your number must be in the range 10000 and 99999.
3: Enter a five-digit number: 01234
ERROR: Your number must be in the range 10000 and 99999.
4:Enter a five-digit number: 991233
ERROR: Your number must be in the range 10000 and 99999.
Explanation / Answer
#! usr/bin/perl
print "Enter a five-digit number: ";
my $num = <>;
print $num;
if($num<=10000)
{
print 'ERROR: Your number must be in the range 10000 and 99999.';
}
elsif($num>=99999)
{
print 'ERROR: Your number must be in the range 10000 and 99999.';
}
else
{
print int($num/10000);
print " ";
print int($num/1000)%10;
print " ";
print int($num/100)%10;
print " ";
print int($num/10)%10;
print " ";
print int($num%10);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.