Computer Science, asked by ruhi668, 11 months ago


3. Write the java programs to find the sum of the following series:
(a) S = a + a² + a3 + .....
.......... + an
(b) S = (a+1) + (a+2) + (a+3) + .......... ...... + (a+n)
(c) S = 2 + + + +
(d) S = 1 + 3 + +
to n
(e) S = a - a3 + 25 - a? + . ..
+
......
to n​

Answers

Answered by sswaraj04
31

Answer:

import java.util.Scanner;

import java.lang.Math;

public class HelloWorld{

    public static void main(String []args){

        Scanner sc=new Scanner(System.in);

       System.out.println("Enter number of terms till you want sum");

       int n=sc.nextInt();

       System.out.println("Enter value of a");

       int a=sc.nextInt();

       int sum=0;

       for(int i=1;i<=n;i++)

       {

           sum+=Math.pow(a,i);

       }

       System.out.println("Sum of series 1 is : "+sum);

       

       sum=0;

       for(int i=1;i<=n;i++)

       {

           sum+=a+i;

       }

       System .out.println("Sum of series 2 is : "+sum);

    }

}

Explanation:

Wrote programs for 1st and 2nd series

Others are not properly written in question

You can use same logic for other series

Just need to change equation for sum

Hope it helps :-)

Similar questions