Computer Science, asked by 7aahilsayed7, 5 months ago

Write a menu-driven program in java to find the sum of the following series :
S = 1 + 1/4! - 2/9! + 3/16! - 4/25!..... n terms where ! denotes factorial of a number (eg. - 5! = 1*2*3*4*5)

Answers

Answered by Arisudhan
1

Answer:

The factorial of a positive number n is given by:

factorial of n (n!) = 1 * 2 * 3 * 4 * ... * n

Example 1: Find Factorial of a number using for loop

public class Factorial {

public static void main(String[] args) {

int num = 10;

long factorial = 1;

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

{

// factorial = factorial * i;

factorial *= i;

}

System.out.printf("Factorial of %d = %d", num, factorial);

}

}

Output

Factorial of 10 = 3628800

In this program, we've used for loop to loop through all numbers between 1 and the given number num (10), and the product of each number till num is stored in a variable factorial.

We've used long instead of int to store large results of factorial. However, it's still not big enough to store the value of bigger numbers (say 100).

For results that cannot be stored in a long variable, we use BigInteger variable declared in java.math library.

hope this helps you. plz mark me as brainlist....

Similar questions