C Program to find the value of cosine of a given angle
Write(*,*)'Enter the value of the angle in degree:'
read(*,*)x
y=(acos(-1.0)*x)/180.0
sum=0.0
term=1.0
i=0
s=1.0
dowhile(abs(term).ge.1.0E-6)
term=(y**i/fact(i))*s
sum=sum+term
i=i+2
s=-s
end do
write(*,10)sum
10 format(2x,'The value of cosx is',f16.4)
end
C Program sub function
function fact(i)
fact=1
do j=1,i
fact=fact*j
end do
return
end
Write(*,*)'Enter the value of the angle in degree:'
read(*,*)x
y=(acos(-1.0)*x)/180.0
sum=0.0
term=1.0
i=0
s=1.0
dowhile(abs(term).ge.1.0E-6)
term=(y**i/fact(i))*s
sum=sum+term
i=i+2
s=-s
end do
write(*,10)sum
10 format(2x,'The value of cosx is',f16.4)
end
C Program sub function
function fact(i)
fact=1
do j=1,i
fact=fact*j
end do
return
end
Comments
Post a Comment