Harmonic Progression Java
PROGRAM TO PRINT SUM OF HARMONIC SERIES
OUTPUT
2.7178571428571425 2.9289682539682538
import
java.io.*;
class
MAIN
{
float
sum(
float
n)
{
// Base condition
if
(n <
2
)
return
1
;
else
return
1
/ n + (sum(n -
1
));
}
// Driven Code
public
static
void
main(String args[])
{
GFG g =
new
GFG();
System.out.println(g.sum(
8
));
System.out.print(g.sum(
10
));
}
}
2.7178571428571425 2.9289682539682538
Comments
Post a Comment