Perl Programming/Exercise 1
From Wikibooks, the open-content textbooks collection
Contents |
[edit] A. Getting started, displaying text
Task: Create a Perl program which displays "Hello world" and then exits.
[edit] B. Displaying numbers
i) Put the number 4000/7 into a variable, and display it on screen.
ii) Adapt the program to display the number to 3 decimal places
iii) Adapt the program to round up if the last decimal place is greater than 5
iv) Adapt the program to display the number with leading zeros
v) Adapt the program to show a + sign if the number is positive, and check that it correctly displays a - sign if you subtract 1000 from the number.
[edit] C. Functions
Write a function to calculate the roots of a quadratic equation, where you give the coefficients a,b,c to the function, and it returns both values of x
[edit] D. Putting it all together
Put together these programs into one which:
- Displays a title on screen
- Creates 3 random numbers (a,b,c)
- Displays those numbers neatly formatted
- Uses those numbers as the coefficients of a quadratic equation, calculates and displays both roots

