- #1
issacnewton
- 1,026
- 36
Hi
Here is my code to get the sum of harmonic series. Harmonic series is
[tex]\sum_{i=1}^{\infty}\; \frac{1}{i} [/tex]
here is the code
Now if I give n= 10000000 , it gives me the answer 15.403683. But Mathematica gives me answer 16.6953. So there is something wrong happening in this simple code.
Can anybody point out the mistake ?
Here is my code to get the sum of harmonic series. Harmonic series is
[tex]\sum_{i=1}^{\infty}\; \frac{1}{i} [/tex]
here is the code
Code:
program harmonic
implicit none
integer :: i,n
real :: sum=0.0
write(*,*)'How many terms you want to sum ?'
read(*,*) n
do i= 1 ,n
sum=sum +(1.0/real(i))
end do
write(*,*) 'The sum of series is = ', sum
end program harmonic
Now if I give n= 10000000 , it gives me the answer 15.403683. But Mathematica gives me answer 16.6953. So there is something wrong happening in this simple code.
Can anybody point out the mistake ?