trying to write a program that will do a truncated infinite series to calculate the sin of x. I need the do loop to end when the term is within the user input for accuracy.
anybody know how i can finish it?
i've got this so far.
Program sinx
Implicit none
!declare variables
real::x, sum, term, accuracy
real::deg2rad=(3.14159/180)
integer::term_number, i
write(*,*)'enter number x in degrees to find sin of x'
read(*,*)x
write(*,*)'Enter required accuracy'
read(*,*)accuracy
!convert x to radians
x=x*deg2rad
write(*,*)'x in radians is ',x
!calculate sum
term_number=1
term = x
sum = 0.0
do i=1, term_number
sum=sum+term
term_number = term_number+1
term = term * (-1) * (x**2)/((2*term_number-2)*(2*term_number-1))
if((abs(sum-(sum+term+1)))<(accuracy))
exit
!evaluate the term and exit the loop if necessary
end do
!display results: sinx and the number of terms required
end program
anybody know how i can finish it?
i've got this so far.
Program sinx
Implicit none
!declare variables
real::x, sum, term, accuracy
real::deg2rad=(3.14159/180)
integer::term_number, i
write(*,*)'enter number x in degrees to find sin of x'
read(*,*)x
write(*,*)'Enter required accuracy'
read(*,*)accuracy
!convert x to radians
x=x*deg2rad
write(*,*)'x in radians is ',x
!calculate sum
term_number=1
term = x
sum = 0.0
do i=1, term_number
sum=sum+term
term_number = term_number+1
term = term * (-1) * (x**2)/((2*term_number-2)*(2*term_number-1))
if((abs(sum-(sum+term+1)))<(accuracy))
exit
!evaluate the term and exit the loop if necessary
end do
!display results: sinx and the number of terms required
end program