Advertisement
riffersfeast

CalculateComplexSum

Mar 6th, 2021
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CalculateComplexSum {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int N = scanner.nextInt();
  7.         int x = scanner.nextInt();
  8.         double S = 1;
  9.         int factorial = 1;
  10.  
  11.         for (int i = 1; i <= N; i++) {
  12.             factorial = factorial * i;
  13.             S = S + factorial / Math.pow(x, i);
  14.         }
  15.         System.out.printf("%.5f", S);
  16.  
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement