- #1

- 21

- 2

Hello I was assigned the following problem:Make a Fortran program which will be able to read a degree[0-360] checking validity range(not type) and it will be able to calculate and print the cos(x) from the following equation:

cos(x)=1-x^2/2! + x^4/4!-x^6/6!+x^8/8!-...,where x is in radiants.As a convergence criteria assume 10^(-5) using the absolute error between two successive repeats(I suppose it means do's).For the calculation of the ! the greatest possible kind of integer should be used.Finally the total number of repeats should be printed on screen.

I have been trying really hard to make it run properly but I still have some questions,which I would be greatful would you be able to answer them.1)How can I measure the diffrence of two succesive repeats?

2)The command iostat will work only for the read it corresponds?

cos(x)=1-x^2/2! + x^4/4!-x^6/6!+x^8/8!-...,where x is in radiants.As a convergence criteria assume 10^(-5) using the absolute error between two successive repeats(I suppose it means do's).For the calculation of the ! the greatest possible kind of integer should be used.Finally the total number of repeats should be printed on screen.

I have been trying really hard to make it run properly but I still have some questions,which I would be greatful would you be able to answer them.1)How can I measure the diffrence of two succesive repeats?

2)The command iostat will work only for the read it corresponds?

Fortran:

```
program askhsh6_ergasia2
implicit none
integer(kind=4)::i,fact,fact2
real,parameter::pi=3.14159265
real::degree,radiants,cosradiants,s
print*,'This program reads and calculates an angle`s co-sinus'
print*,'Please input the degrees of the angle'
read*,degree
do while(degree<0 .or. degree>360)
read*,degree
print*,'Error input degree'
cycle
end do
radiants=(degree*pi/180)
fact=1
fact2=1
s=0
do i=2,100,2
fact=fact*i
fact2=fact2*(i+2)
cosradiants=(-(radiants)**i/fact)+(((radiants)**(i+2))/fact2)
s=s+cosradiants
end do
print*,s+1.
end program
```

Last edited by a moderator: