Series Based Questions
Series Based Questions
S = a2 + a2 / 2 + a2 / 3 + …… + a2 / 10
import java.util.Scanner;
S = a + a2 / 2 + a3 / 3 + …… + a10 / 10
import java.util.Scanner;
System.out.print("Enter a: ");
int a = in.nextInt();
double sum = 0.0;
sum += Math.pow(a, i) / i;
import java.util.Scanner;
System.out.print("Enter x: ");
int x = in.nextInt();
System.out.print("Enter n: ");
int n = in.nextInt();
double sum = 0;
int a = 1;
sum += term;
a *= -1;
(a) To find and display the sum of the series given below:
switch (choice) {
case 1:
int sum = 0;
for (int i = 1; i <= 20; i++) {
int term = (int)Math.pow(2, i);
if (i % 2 == 0)
sum -= term;
else
sum += term;
}
System.out.println("Sum=" + sum);
break;
case 2:
int term = 1;
for (int i = 1; i <= 5; i++) {
System.out.print(term + " ");
term = term * 10 + 1;
}
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
}
5-Write a program to compute and display the sum of the following series:
import java.util.Scanner;
public class AtpStem
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter n: ");
int n = in.nextInt();
double sum = 0.0;
for (int i = 2; i <= n; i++) {
double num = 0.0, den = 1.0;
for (int j = 1; j <= i; j++) {
num += j;
den *= j;
}
sum = sum + (num / den);
}
System.out.println("Sum=" + sum);
}
}
S = 1! + 2! + 3! + …. + n!
import java.util.Scanner;
D
S = 1 + (x+2)/2! + (2x+3)/3! + (3x+4)/4! + ……… to n terms
import java.util.Scanner;
double series(double n) {
double sum = 0;
return sum;
double sum = 0;
int x = 1;
int e = x + 1;
sum += term;
x += 3;
return sum;
o
}
9-Write the program in Java to display the first ten terms of the
following series:
1, 9, 25, 49,
11-Write the program in Java to display the first ten terms of the
following series:
0, 3, 8, 15,
void sumSeries() {
long sum = 0, term = 1;
for (int i = 1; i <= 20; i++) {
term *= i;
sum += term;
}
System.out.println("Sum=" + sum);
}
}
13-Write the program in Java to display the first ten terms of
the following series:
2, 5, 10, 17,
1 + 4 + 9 + …… + 400
2 - 4 + 6 - 8 + …… - 20
S = 1 + 22 / a + 33 / a2 + …… to n terms
import java.util.Scanner;
import java.util.Scanner;
import java.util.Scanner;
System.out.println("Sum=" + sum);
}
}
import java.util.Scanner;
0, 1, 2, 3, 6,
int a = 0, b = 1, c = 2;
}
}
S = 1 + 1 + 2 + 3 + 5 + ……. to n terms
import java.util.Scanner;
int a = 1, b = 1;
int sum=a+b ;
System.out.println("Sum=" + sum);
}
}
29 Write a program in Java to find the sum of the following
series:
import java.util.Scanner;
import java.util.Scanner;
}
}
32 Write a program in Java to input the values of x and n and
print the sum of the following series:
import java.util.Scanner;
if (n % 2 != 0) {
System.out.println("n should be even");
return;
}
double sum = 0;
int a = 1;
for (int i = 0; i <= n; i += 2) {
long f = 1;
for (int j = 1; j <= i; j++) {
f *= j;
}
double t = Math.pow(x, i) / f * a;
sum += t;
a *= -1;
}
import java.util.Scanner;
if (isPrime) {
sum += j / Math.pow(a, i);
lastPrime = j;
break;
}
}
}
System.out.println("Sum=" + sum);
}
}
34 Factorial- Using switch statement write a menu driven
program to overload a function series as follows:
(a) void series() — To find and display the sum of the following
series:
S = 2 - 4 + 6 - 8 + 10 ….. - 20
(b) void series(int n, int x) — To find and display the sum of the
following series:
import java.util.Scanner;
case 2:
System.out.print("Enter x: ");
int x = in.nextInt();
System.out.print("Enter no. of terms(n): ");
int n = in.nextInt();
obj.series(n, x);
break;
default: BE
System.out.println("Incorrect Choice");
}
}
}