Findout Factorial of Number and Sum of Factorial Series -Java Program

package Prog;
import java.util.Scanner;


public class Factorial
{

public static void main(String args[])
{
int n;

Scanner sc=new Scanner(System.in);
System.out.println("Enter the no.  for factorial");
n=sc.nextInt();

int f=1;
int sum=0;
for(int i=1;i<=n;i++)
{
f=f*i;
sum=sum+f;
}

System.out.println(" Factorial of "+n+" is ="+f);
  System.out.println(" Sum of Factorail Series of "+n+" is ="+sum); 

}

}

Output:
--------------------------------------------------------------------------------------------------------------------------
Enter the no. for factorial:-
5

 Factorail of 5 is =120
 Sum  of Factorail Series of 5 is =153
53



Post a Comment

0 Comments