forked from miladsade96/FCS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroots.f90
More file actions
25 lines (24 loc) · 805 Bytes
/
roots.f90
File metadata and controls
25 lines (24 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
! Created by EverLookNeverSee@GitHub on 4/15/20.
! This program calculates the roots of a quadratic equaion.
program roots
implicit none
! defining variables
real :: a, b, c, x_1, x_2, delta, sr_delta
! getting user input
print *, "Enter the values of a, b, c:"
read *, a, b, c
! calculating delta
delta = (b ** 2) - (4.0 * a * c)
if (delta > 0.0) then
sr_delta = sqrt(delta)
x_1 = (-b + sr_delta) / (2.0 * a)
x_2 = (-b - sr_delta) / (2.0 * a)
print *, "roots are:", x_1, x_2
elseif (delta == 0.0) then
x_1 = -b / (2.0 * a)
x_2 = x_1
print *, "roots are equal:", x_1, x_2
else ! value of delta is less than 0.0
print *, "This quadratic equation has no real root."
end if
end program roots