Computer Science, asked by abhinavjain1307, 10 months ago

write a program in java to find the sum of the series :


x¹-x²+x³-x⁴+..........xn​

Answers

Answered by muralikrithi
34

Answer:

Explanation:

import java.util.*;

class series

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

int sum=0;

System.out.println("Enter the n th number");

int n=sc.nextInt();

System.out.println("Enter  x ");

int x=sc.nextInt();

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

{

if(i%2==0)

{

sum=sum-Math.pow(x,i);

}

else if(i%2!=0)

{

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

}

}

System.out.println("Sum = "+sum);

}

}

Hope this program helps you,

Thanks

Answered by syed2020ashaels
0

Answer:

Given below is the answer

Explanation:

A Java programme to find the sum of the series 1/1! + 2/2! + 3/3! +...N/N! is provided here.

Enter the desired number of terms for the series in the input field. We now compute the sum and obtain the desired outcome using factorials and loops.

The Java Program to Find Sum of the Series 1/1! + 2/2! + 3/3! +...N/Nsource !'s code is available here. On a Windows system, the Java programme is successfully compiled and executed. Also given below is the output of the application.

import java.util.Scanner;

public class Sum_Series

{

   public static void main(String[] args)

   {

       double sum = 0;

       int n;

       System.out.println("1/1! + 2/2! + 3/3! + ..N/N!");

       Scanner s = new Scanner(System.in);

       System.out.print("Enter the no. of terms in series:");

       n = s.nextInt();

       Sum_Series obj = new Sum_Series();

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

       {

           sum = sum + (double)i / (obj.fact(i));

       }

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

   }

   int fact(int x)

   {

       int mul = 1;

       while(x > 0)

       {

           mul = mul * x;

           x--;

       }

       return mul;

   }

}

See more:

https://brainly.in/question/1392576

#SPJ3

Similar questions