-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumSeries.java
More file actions
50 lines (46 loc) · 959 Bytes
/
SumSeries.java
File metadata and controls
50 lines (46 loc) · 959 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
50
import java.util.*;
public class SumSeries
{
int x;
int n;
double sum;
SumSeries()
{
x=0;
n=0;
sum=0.0;
}
void readline()
{
Scanner as= new Scanner(System.in);
System.out.print("\t -SUM OF SERIES-\n");
System.out.print("Enter the Number of Terms(n):");
n=as.nextInt();
System.out.print("Enter The Value for X:");
x=as.nextInt();
}
int getPower(int m, int p)
{
if(p==0)
return 1;
return(m*getPower(m,(p-1)));
}
void sum()
{
int i,k;
double a,b;
for(i=1,k=2;i<=n;i++,k+=2)
{
a=getPower(x,k);
b=getPower(i,i);
sum+=a/b;
}
System.out.println("The Sum of the Series:"+sum);
}
public static void main(String[] args)
{
SumSeries as1=new SumSeries();
as1.readline();
as1.sum();
}
}