Advertisement
aneliyanestorova

complex sum

Apr 9th, 2019
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class ComplexSum {
  3. public static void main(String[] args) {
  4. // S=1+1!/x+2!/x^2+⋯+N!/x^N
  5.  
  6. Scanner scanner = new Scanner(System.in);
  7. int n = Integer.parseInt(scanner.nextLine());
  8. double x = Double.parseDouble(scanner.nextLine());
  9. int result = 1;
  10.  
  11. for (int i = 1; i <= n; i++) {
  12. result = result * i;
  13.  
  14. // System.out.print(result);
  15.  
  16. double xn = result/(Math.pow(x, i));
  17.  
  18. // System.out.println(xn);
  19. double sum = 1+(xn);
  20.  
  21. System.out.printf("%.5f", sum);
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement