Q2. Write a program In java
Attachments:
Answers
Answered by
3
Question:
- WAP in Java to print the sum of this series.
Answer:
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter n and x");
int x=sc.nextInt();
int n=sc.nextInt();
double s=0,fact=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
fact*=j;
}
s=(i%2==0)?(s+fact)/x:(s-fact)/x;
}
System.out.println("Sum:"+s);
}
}
•Output Attached
•••♪
Attachments:
Similar questions
Business Studies,
1 month ago
Math,
1 month ago
Math,
3 months ago
Environmental Sciences,
3 months ago
Math,
10 months ago
English,
10 months ago