[perkins][lab2-2][~/Lecture7] perl EvenOrOdd.pl Enter your number: 3 The number 3 is odd. [perkins][lab2-2][~/Lecture7]You may want to use the % operator in your program, though there are ways of figuring out whether a number is even or odd without using %.
$Count = <>; chomp $Count; while ( $Count >= 0 ) { print "$Count\n"; $Count--; }Consider a slightly different version of this program, which we'll call version 2:
$Count = <>; chomp $Count; while ( $Count > 0 ) { print "$Count\n"; $Count--; }Or consider another variant, which we'll call version 3:
$Count = <>; chomp $Count; while ( $Count > 0 ) { $Count--; print "$Count\n"; }How do the outputs of these three versions of the program differ? You may want to enter these programs and run them on your computer. But you may also want to try running them "in your head" -- that is, think through how the programs would run and what output they would produce for different inputs. In particular, think how the different versions would run if the user entered different values for $Count. What do they output if $Count starts at 0? At 1? At 2? Etc.
(-b + sqrt(b2 - 4ac)) / 2a
and
(-b - sqrt(b2 - 4ac)) / 2a
In these to formulas, sqrt indicates computing the square root. Write a program that asks the user to input values for a, b and c, computes the two values of x that satisfy the quadratic equation ax2 + bx + c = 0. For simplicity, you may assume that b2 - 4ac is greater than or equal to zero. (Otherwise, the solutions are complex numbers, not reals, and Perl will complain when you try to take the square root.) For example, a run of the program might look like:
[perkins][lab2-2][~/Lecture7] perl Quad.pl Enter a: 1 Enter b: -6 Enter c: 8 The values of x that satisfy the equation are 4 and 2. [perkins][lab2-2][~/Lecture7]P.S. You can check whether your program has computed the correct possibilities for x by substituting them back into the formula ax2 + bx + c and checking that it comes out to zero.
(-b / 2a) + (sqrt(-b2 + 4ac) / 2a)i
and
(-b / 2a) - (sqrt(-b2 + 4ac) / 2a)i
Write a program that asks the user to input values for a, b and c. If b2 - 4ac is greater than or equal to zero, output the two real values of x that solve the quadratic equation. If b2 - 4ac is negative, output the two complex values of x that solve the equation. For example, a run of the program might look like:
[perkins][lab2-2][~/Lecture7] perl Quad2.pl Enter a: 1 Enter b: -6 Enter c: 8 The values of x that satisfy the equation are 4 and 2. [perkins][lab2-2][~/Lecture7] perl Quad2.pl Enter a: 1 Enter b: -2 Enter c: 2 The values of x that satisfy the equation are 1+1i and 1-1i. [perkins][lab2-2][~/Lecture7]
[perkins][lab2-2][~/Lecture7] perl StarRow.pl How many stars? 10 ********** [perkins][lab2-2][~/Lecture7]
[perkins][lab2-2][~/Lecture7] perl StarTriangle.pl Enter a number? 10 * ** *** **** ***** ****** ******* ******** ********* ********** [perkins][lab2-2][~/Lecture7]