-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYT19.java
More file actions
56 lines (49 loc) · 1.03 KB
/
YT19.java
File metadata and controls
56 lines (49 loc) · 1.03 KB
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
50
51
52
53
54
55
56
class YT19
{
public void Series()
{
int a=1;
int c=0;
int b=0;
for(int i=0; i<=10; i++)
{
c=a+2*b;
System.out.print(c + " ");
a=b;
b=c;
}
}
public double Series(int x, int n)
{
double e=0, fact=1, sum=0;
//int s;
for(int i=1; i<n; i++)
{
e=i;
for(int j=1; j<=e; j++)
{
fact=fact*j;
}
if(e%2!=0)
{
sum=sum-Math.pow(e,x)/fact;
}
else
{
sum=sum+Math.pow(e,x)/fact;
}
fact=1;
}
//s=(int)sum;
return Math.floor(sum);
}
public static void main(String[] args)
{
double c;
YT19 Y1 = new YT19();
Y1.Series();
//Y1.Series(2, 6);
c=Y1.Series(3, 6);
System.out.println("\n"+c);
}
}