Source code of summation of Harmonic series in java
Saturday, March 21, 2009
import java.io.*; class Harmonic { public static void main(String args[])throws IOException { String a; float b; BufferedReader BR=new BufferedReader(new InputStreamReader(System.in)); a=BR.readLine(); b=Float.parseFloat(a); float c; float sum=0; for(float i=1;i<=b;i++) { c=1/i; sum=sum+c; } System.out.printf("%f\n",sum); } }
0 comments:
Post a Comment