CS
1401 Introduction to Computer Science
Fall 2014, Lab 3
Assignment. Write a program that prompts the user to input
three real numbers and prints these numbers in non-decreasing order.
Hint: you need to consider all possible orders between the three
numbers x1, x2, and x3. We separately consider cases when x1 is the
largest, when x2 is the largest, and when x3 is the largest:
- if x1 ≤ x2 ≤ x3 then we print the values x1, x2, x3;
- if x1 ≤ x3 ≤ x2 then we print the values x1, x3, x2;
- if x2 ≤ x1 ≤ x3 then we print the values x2, x1, x3;
- if x2 ≤ x3 ≤ x1 then we print the values x2, x3, x1;
- if x3 ≤ x1 ≤ x2 then we print the values x3, x1, x2;
- if x3 ≤ x2 ≤ x1 then we print the values x3, x2, x1.
For extra credit: write a program that computes the roots of a
quadratic equation a * x2 + b * x + c = 0; formulas are
given, e.g., in Problem 3.1. Please note that we are only interested
in real solutions; for example, for the equation
x2 + 1 = 0, your program should return a message that
this equation does not have any solutions.
When it is due. The program is due at the beginning of the
first lab section on the week of September 22, i.e.:
- on
Monday September 22 for those who attend Monday-Wednesday labs,
and
- on Tuesday September 23 for those who attend
Tuesday-Thursday labs.