Computer Science, asked by Sneha591, 9 months ago

WAP in java to print the sum of all the factorials of number between 1 to 10.​

Answers

Answered by RAAZ34
0

Answer:

Explanation:

Here, we are implementing a java program that will read the value of N and find sum of the factorials from 1 to N. It is a solution of series 1! + 2! + 3! + 4! + ... N! in java.

Submitted by Chandra Shekhar, on January 06, 2018

Given N and we have find the solution of series 1! + 2! + 3! + 4! + ... N! using Java program. (Sum of the factorials from 1 to N).

Example:

   Input: 3

   Output: 9

   Explanation:

   1! + 2! + 3! = 1 + 2 + 6 = 9

   Input: 5

   Output: 152

   Explanation:

   1! + 2! + 3! + 4! + 5!

   = 1+2+6+24+120

   = 153

Answered by garvitguptark
0

Answer:

input:  

public class SumOfFactorial

{

public static void main(String[] args)

{

 // create scanner class object.

 Scanner sc = new Scanner(System.in);

 

 // enter the number.

 System.out.print("Enter number : ");

 int n = sc.nextInt();

 

 int total=0;

 

 int i=1;

 

 // calculate factorial here.

 while(i <= n)  

 {

  int factorial=1;

  int j=1;

   

  while(j <= i)  

  {

   factorial=factorial*j;

   j = j+1;

  }

  // calculate sum of factorial of the number.

  total = total + factorial;

  i=i+1;

 }

 // print the result here.

 System.out.println("Sum : " + total);

}

}

Explanation:

output:

First run:

Enter number : 3

Sum : 9

Second run:

Enter number : 5

Sum : 153

Similar questions