0% found this document useful (0 votes)
63 views12 pages

Ques12-Write A Program To Find The Sum of Series: - S 1 + A + A A + A A A+ .10 Power

The document contains 18 questions related to writing Java programs to calculate various mathematical series. For each question, the Java code to calculate the specified series is provided, along with an explanation of the algorithm used in 2-3 sentences. The questions cover topics like calculating power series, Fibonacci series, alternating series, factorial series, and series defined by user input.

Uploaded by

MishraAviral
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views12 pages

Ques12-Write A Program To Find The Sum of Series: - S 1 + A + A A + A A A+ .10 Power

The document contains 18 questions related to writing Java programs to calculate various mathematical series. For each question, the Java code to calculate the specified series is provided, along with an explanation of the algorithm used in 2-3 sentences. The questions cover topics like calculating power series, Fibonacci series, alternating series, factorial series, and series defined by user input.

Uploaded by

MishraAviral
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Ques12- Write a program to find the sum of

series:S=1 + a + a*a + a*a*a+


.10 power.
import java.io.*;
class series
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int i,a;
double s=1;
System.out.println("Enter value of a");
a=Integer.parseInt(in.readLine());
for(i=1;i<=10;i++)
{
s=s+Math.pow(a,i);
}
System.out.println("sum is"+s);
}

Algorithm-

1. Accepts the value of a from the user and stores it in


variable a.
2. Loop executesfor(i=1;i<=10;i++)
{
s=s+Math.pow(a,i);

// mathematical function is used

which sends i to
power of a and sum is
stored in s
}

3. Sum is displayed.

Ques13- Write a program to print the first 10


numbers of fibonacci series.
public class fibonnaci
{
public static void main(String args[])
{
int a,b,c,n;a=0;b=1;c=0;n=3;
System.out.println("The fibonnaci series is");
System.out.println(a);
System.out.println(b);
do
{
c=a+b;

System.out.println(c);
a=b;
b=c;
n=n+1;
}
while(n<=10); }}

Algorithm1. Initialize a=0, b=1 and c=0.


2. Display a and b
3. Set n=3 and it acts as counter variable.
4. Repeat through step 7 while(n<10).
5. Sum is found and stored in c of a and b.
6. Set a=b and b=c.
7. Value of counter variable increases with 1n=n+1;

8. Stop.

Ques14- Write a program to find sum of series:S=1 - + 1/3 -1/4 + ..-1/10.


public class ser
{
public static void main(String args[])
{
float a,s;s=0;
for(a=1;a<=10;a++)
{
if(a%2==0)
s=s-1/a;
else
s=s+1/a;
}
System.out.println("Sum is"+s);
}
}

Algorithm1. Initialize s=0.

2. Loop executesfor(a=1;a<=10;a++)
{
if(a%2==0)

// checks number is even or not

// if the above condition is true then


subtraction is done
s=s-1/a;
else

// if condition is false then add in a


common variable s
s=s+1/a;
}

3. Sum is displayed.

Ques15-Write a program to find sum of series:S= 1+(1*2)+(1*2*3)+..10 terms.


public class series
{
public static void main(String args[])
{
int a,s,p;s=0;p=1;
for(a=1;a<=10;a++)
{
p=p*a;

s=s+p;
}
System.out.println("sum is"+s);
}
}

Algorithm1. Initialize s=0 and p=1.


2. Loop executesfor(a=1;a<=10;a++)
{
p=p*a;
s=s+p;

product
}

3. Sum is displayed.

// multiplication is done
// sum is found each time of the

Ques16-Write a program to display series:1,11,111,1111


public class display
{
public static void main(String args[])
{
int a,p;
double s;s=0;
for(a=0;a<=7;a++)
{
s=s+Math.pow(10,a);
p=(int)s;
System.out.print(p+",");
}
}
}

Algorithm1. Initialize s=0.

2. Loop executesfor(a=0;a<=7;a++)
{
s=s+Math.pow(10,a);

// mathematical function is

used which sends


a to the power of 10
and sum is stored in s
p=(int)s;

// type casting is done to

convert p to int
System.out.print(p+",");
}

3. Sum is displayed.

Ques17- Write a program to find the sum of the


given series after accepting the value of n from
the user:
S=2 + 5 + 10 + .to n
terms
import java.io.*;
class seriessq
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader (read);

int s;s=0;int i;
System.out.println("Enter value of n");
int n=Integer.parseInt(in.readLine());
for(i=1;i<=n;i++)
{
s=s+(1+(i*i));
}
System.out.println("Sum is "+s);
}
}

Algorithm1. Accept the value of n from the user.


2. Loop startsfor(i=1;i<=n;i++)

// loop runs from 1 to n

{
s=s+(1+(i*i));

of i and adds 1 to

// first finds square of the value

it and finds sum and stores


in s
}

3. Displays the results.

Ques18- Write a program to find the sum of the


given series after accepting the value of n from
the user:
S= (1*2)/(1+2) + (2*3)/(2+3) to n
terms.
import java.io.*;
class series2
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader (read);
double s;s=0;int i;
System.out.println("Enter value of n");
int n=Integer.parseInt(in.readLine());
for(i=0;i<=n;i++)

{
s=(double)(s+(float)(i*(i+1))/(i+(i+1)));
}
System.out.println(s);
}
}

Algorithm1. Accept the value of n from the user.


2. Loop runsfor(i=0;i<=n;i++)

// runs till n

{
s=(double)(s+(float)(i*(i+1))/(i+(i+1)));

// find sum according

to following step
and by type casting
converts it to double type
}

3. Stop.

You might also like