Friday, 13 December 2013

Unknown

Write a program to generate Harmonic Series.

/*Example 
 Input - 5
 Output - 1 + 1/2 + 1/3 + 1/4 + 1/5 = 2.28 (Approximately) */

class HarmonicSeries {

    public static void main(String args[]) {
        int num = Integer.parseInt(args[0]);
        double result = 0.0;
        while (num > 0) {
            result = result + (double) 1 / num;
            num--;
        }
        System.out.println("Output of Harmonic Series is " + result);
    }
}

Unknown

About Blog No Baap -

Since 2016 BlogNoBaap has been bringing you the very best in all types of web resources. Posted daily, and delivered straight to your inbox each morning.

Subscribe to this Blog via Email :