Advertisement
Codex

Sum Series

Jul 27th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.39 KB | None | 0 0
  1. /*
  2. Find sum of series
  3. 1+x/1!+x2/2!+x3/3! upto n times
  4. */
  5. import java.util.Scanner;
  6. public class SumSeries
  7. {
  8. public static void main(String args[])
  9. {
  10. int n,i,fact=1,j;
  11. double sum=0;
  12. Scanner sc=new Scanner(System.in);
  13. System.out.println("Enter limit");
  14. n=sc.nextInt();
  15. for(i=1;i<=n;i++)
  16. {
  17. fact=1;
  18. for(j=1;j<=i;j++)
  19. fact=fact*j;
  20. sum+=(double)i/fact;
  21. }
  22. System.out.println(sum);
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement