design a class to overloaded function series ( ) as follows:1.double series (doublr n)with one double argument and returns the sum of the series sum=1/1+1/2+1/3+.....+1/n 2.double series (double a ,double n)with two double arguments and returns the sum of the series sum=1/a^2+1/a^5+1/a^8+1/a^11+......+to n terms.
Please answer it very fast
Answers
Answered by
32
1.
import java.io.*;
class GFG {
static double series(double n)
{
double i, s = 0.0;
for (i = 1; i <= n; i++)
s = s + 1/i;
return s;
}
public static void main(String args[])
{
int n = 5;
System.out.printf("Sum is %f", series(n));
}
}
I don't understand the 2nd question.
Answered by
5
Answer:
import java.util.*;
class overload
{
double series (double n)
{
double I,s=0.0;
for(I=1;I<=n,I++)
s=s+1/I;
return s;
}
double series (double a, double n)
{
double I,j,sum=0.0;
for(I=1;I=2;I<=n*3;I+=3;j+=3)
sum=sum+I/Math.pow(a,j);
return sum;
}
}
Similar questions
English,
5 months ago
Computer Science,
5 months ago
India Languages,
5 months ago
Biology,
11 months ago
Biology,
11 months ago
Math,
1 year ago
English,
1 year ago