Example 1. State The Problem: Input

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Example 1.

State the problem


Design and write a program to solve for the real The problem statement for this example is very
roots of a quadratic equation. simple. We want to write a program that will solve
for the real roots of a quadratic equation, whether
they are distinct real roots, or repeated real roots.

1 2

2. Define input and outputs 3. Design algorithm


Input: This task can be broken down into three major
sections, whose functions are input, processing,
The inputs required by this program are
and output:
coefficients , , and of the quadratic equation
Read the input data
+ + =0
Calculate the roots
Output: Write out the roots

The output from the program will be the real roots We will now break each of the above major
of the quadratic equation, whether they are distinct sections into smaller, more detailed pieces.
real roots, or repeated real roots.
3 4

4. Pseudocode 4. Pseudocode
Prompt the user for the coefficients a, b, and c. IF discriminant < 0 THEN
Read a, b, and c Write message that equation has no real roots.
Echo the input coefficients ELSE IF discriminant > 0 THEN
discriminant ← b**2 - 4. * a * c x1 ← (-b + sqrt(discriminant)) / (2. * a )
x2 ← (-b - sqrt(discriminant)) / (2. * a )
Write message that equation has two distinct real
roots.
Write out the two roots

5 6
4. Pseudocode
ELSE
x1 ←-b / (2. * a)
Write message that equation has two identical
real roots.
Write out the repeated root.
END IF

You might also like