Computer Programming with Engineering Applications
CS 2073
Computer Programming with Engineering Applications
Assignment 2
1. (100 pts) Write a program that determines the roots of a quadratic equation. Given an
equation of the form
ax2 + bx + c = 0 (1)
The roots of the equation can be computed using the formula
x1,2 = −b∓
√ b2 − 4ac
2a (2)
Your program should read the coefficients from user and display one the following messages
depending on the value of roots.
• No real roots This means b2 − 4ac < 0
• Two equal roots This means b2 − 4ac = 0
• Two distinct roots This means b2 − 4ac > 0
Test your program for the following cases
(a) Equation is of the form ax^2+bx+c=0
Enter a, b, c:
1 2 1
Two equal roots
(b) Equation is of the form ax^2+bx+c=0
Enter a, b, c:
1 3 1
Two distinct roots
(c) Equation is of the form ax^2+bx+c=0
Enter a, b, c:
1 1 1
No real roots
Submit your program electronically using the blackboard system
The program you submit should be your own work. Cheating will be reported to office of academic
integrity. Both the copier and copiee will be held responsible.