Design N Class to Overload a Function Sumserieso as Follows: (I) Void Sumseries(Int N, Double X) – with One Integer Argument and One Double Argument to Find and Display
Advertisements
Question
Design n class to overload a function SumSeriesO 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"/1 - "x"/2 + "x"/3 - "x"/4 + "x"/5`...... ...... ...... to n terms
(ii)
void SumSeries() – To find and display the sum of the following series:
s = 1 + (1 x 2) + (1 x 2 x 3) + ….. + (1 x 2 x 3 x 4 x 20)
Advertisements
Solution
class Overload
{
void SumSeries (int n, double x)
{
double sum = 0;
for (int k = 1; k<=n; k++)
{
t = x / k;
if (k% 2 = = 1)
sum = sum + t:
else
sum = sum - t:
}
System.out.println ("sum is" + sum);
}
void SumSeries ()
{
long f, s = 0;
for (int a = 1; a<=20; a++)
{
f = 1;
for (int b = 1; b <=a; b++)
}
f = f ∗ b;
}
S = S + f;
}
System.out.println ("Sum" + S);
}
}
