C Program to find the sum of the e^x series with an error < 10^5
write(*,*)'Enter the value of x:'
read(*,*)x
sum=0.0
term=1.0
i=1
10 sum=sum+term
term=x**i/fact(i)
k=k+1
i=i+1
if(abs(term).gt..00001)goto 10
write(*,20)sum,x
20 format(2x,'The sum of the series is:'f16.4,' for x=',f16.4)
end
C Program sub function
function fact(i)
fact=1.0
do j=1,i
fact=fact*j
end do
return
end
write(*,*)'Enter the value of x:'
read(*,*)x
sum=0.0
term=1.0
i=1
10 sum=sum+term
term=x**i/fact(i)
k=k+1
i=i+1
if(abs(term).gt..00001)goto 10
write(*,20)sum,x
20 format(2x,'The sum of the series is:'f16.4,' for x=',f16.4)
end
C Program sub function
function fact(i)
fact=1.0
do j=1,i
fact=fact*j
end do
return
end
Comments
Post a Comment