PREE HW#5 - HW#5 1.1/usr/local/bin/perl-w Tzu-Ying...

Info icon This preview shows pages 1–3. Sign up to view the full content.

HW#5 Tzu-Ying Hsu(9083) 1.1 #!/usr/local/bin/perl -w #This program finds the smallest of a list of number. $smallest = 100000; while(<STDIN>) { if($_ < $smallest) { $smallest = $_; } } print("The smallest is: $smallest\n"); #End of the program 1.2 #!/usr/local/bin/perl -w #This program changes a decimal to a binary number. $" = " "; print("Enter a decimal number: "); $dec = <STDIN>; while($dec > 0) { $rem = $dec % 2; $dec = int ($dec / 2); unshift (@bin, $rem); } print("The binary number is: @bin\n"); #End of the program 1.3 #!/usr/local/bin/perl -w #This program prints lines 5, 10, 15, ... while(<STDIN>) { if($. % 5 == 0) { print($_); } } #End of the program 1.4 #!/usr/local/bin/perl -w
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

#This program uses an array to do looping @arr = (1 .. 5); foreach(@arr) { $_ ++; } print("@arr\n"); #End of the program 1.5 #!usr/local/bin/perl -w #This program prints a string reversed. print("Please type a string: "); $" = " "; chomp($string = <STDIN>); $len = length($string); foreach(1 .. $len) { push(@array, chop($string)); } print("@array\n"); #End of the program 1.6 #!usr/local/bin/perl -w #This program prints a string vertically. print("Please type a string: "); chomp($string = <STDIN>); $len = length($string); foreach(1 .. $len) { unshift(@array, chop($string)."\n"); } print(@array);
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '10
  • alex
  • Binary numeral system, Positional notation, Decimal, Binary-coded decimal, Numeral system

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern