Computer Science, asked by ShivHalvawala, 4 months ago

Write a java programme to find the sum of series:

S=1/2-2/3+3/4-4/5.....-10/11

plzzzz try to answer fast if u know the full answer

it is urgent

class 10 icse board 2020-2021​​

Answers

Answered by anindyaadhikari13
2

Required Answer:-

Question:

Write a Java program to display the sum of the series

½ - ⅔ + ¾ ...... - 10/11

Solution:

Here is the code.

  1. public class SumOfSeries {
  2. public static void main(String[] args) {
  3. double s=0;
  4. for(int i=1;i<=10;i++)
  5. {
  6. if(i%2==1)
  7. s+=i/(double)(i+1);
  8. else
  9. s-=i/(double)(i+1);
  10. }
  11. System.out.println("Sum: "+s);
  12. }
  13. }

Explanation:

  • Each term of the series is in the form of n/(n + 1) where n = 1,2,3,..10.The series goes in an alternating fashion. First term is added to the sum and then the next term is subtracted from the sum. We have created a loop that iterates 10 times (i = 1 to 10). Here the control variable is 'i'. If 'i' is odd, then we will add the value else we will subtract.

Output is attached.

Attachments:
Similar questions