-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExercise_07.f90
43 lines (41 loc) · 1.33 KB
/
Exercise_07.f90
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
! Created by EverLookNeverSee@GitHub on 5/31/20
! For more information see FCS/img/Exercise_07.png
program main
implicit none
! declaring variables
integer :: i, degree
real :: x, result = 0.0
real, allocatable, dimension(:) :: P ! to store polynomial coefficients
! specifying polynomial degree using user input
do
print *, "Enter degree of the polynomial:"
read *, degree
if (degree < 0) then
print *, "Degree should not be negative!"
cycle
end if
exit
end do
! creating array blocks based on polynomial degree
allocate(P(degree + 1))
! when we have constant(degree of zero) equation
if (degree == 0) then
print *, "Please enyter your single value(intercept):"
read *, P(1)
result = P(1)
else ! for upper degrres of equations
print *, "Please enter the value of x:"
read *, x
print *, "Please enter polynomial coeffs using the form below:"
print *, "ax**0 +- bx**1 +- cx**2 +- ... +- dx**n"
do i = 1, size(P)
print *, "Enter cefficient of x**", i - 1, ":"
read *, P(i)
end do
do i = size(P), 1, -1
result = result * x + P(i)
end do
end if
! printing the result
print *, "Result:", result
end program main