-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumseries.java
More file actions
49 lines (44 loc) · 801 Bytes
/
Copy pathSumseries.java
File metadata and controls
49 lines (44 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
class Sumseries
{
int X,n;
double sum;
Sumseries()
{
X=0;
n=0;
sum=1.0;
}
int factorial(int n)
{
int fact=1;
for(int i=1;i<=n;i++)
fact=fact*i;
return fact;
}
double term(int p,int q)
{
return p/factorial(q);
}
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter value of X and n");
X=sc.nextInt();
n=sc.nextInt();
}
void displaysum()
{
System.out.println("Sum of series="+sum);
}
double calsum()
{
int p,q,j=1;
for(int i=1;i<=(2*n)-1;i=i+2)
{
sum+=term((int)Math.pow(X,i),j);
j++;
}
return sum;
}
}