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
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
1 Comments
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeletePython Training in electronic city
DataScience with Python Training in electronic city
AWS Training in electronic city
Big Data Hadoop Training in electronic city
Devops Training in electronic city