Class 10th ICSE

Q.2

 Design a class to overload a function sumSeries() as follows:
(i) void sumSeries(int n,double x)-with one integer argument and one double
argument to find and display the sum of the series given below
s=x-x/2+x/3-x/4+x/5…………n terms
(ii) void sumSeries()- To find and display the sum of the following series:
s=1+(1*2)+(1*2*3)+………………..+(1*2*3……*20)

Solution :- 

class p1{
void sumseries(int n,double x){
int i,a=1;
double s=0.0;
for(i=1;i<=n;i++){
s=s+x/a;
x=x*-1;
a++;
}
System.out.println(“Sum of series =”+s);
}
void sumseries(){
double s=0.0;
int i,f;
for(i=1;i<=20;i++){
f=1;
for(int j=1;j<=i;j++){
f=f*j;
}
s=s+f;
}
System.out.println(“Sum of series =”+s);
}
public static void main(){
p1 obj =new p1();
obj.sumseries(2,2);
obj.sumseries();
}
}

Fun & Easy to follow
Works on all devices
Your own Pace
Super Affordable

Popular Videos

Play Video

UX for Teams

Learn the basics and a bit beyond to improve your backend dev skills.

ava4.png
Chris Matthews

Designer

Play Video

SEO & Instagram

Learn the basics and a bit beyond to improve your backend dev skills.

ava4.png
Chris Matthews

Designer