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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
#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));
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/11/2010 for the course MSEE 1 taught by Professor Alex during the Spring '10 term at Northwestern Polytechnic University.

Page1 / 5

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

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online