1/2+1/3+1/4.....1/20 write a program in java to print the sum of series
Answers
Answered by
12
Following are the program which is given below
Output:
Sum is: 3.5977396
Explanation:
class Main // main class
{
public static void main(String args[]) // main method
{
double s1=0.0,k; // variable declaration
for (k = 1; k <=20; k++) // iterating loop
{
s1 = s1 + ( 1/k); // calculating sum
}
System.out.print("Sum is: " +s1); // print value
}
}
Following are the description of program
- Declared a variable "s1' and "k" of "double" type also initialized s1 to 0.0.
- Iterating the for loop to the 20 times .In this calculating the sum of series
- Finally from outside the loop we print the value of "s1 " variable .
Learn More :
- brainly.in/question/3544030
Similar questions