Computer Science, asked by taniakhan38, 5 months ago

Write a menu-driven program to print the following series according to user's choice:-
(i) s= 1+4+9+......+n terms
(ii) s= a+a/2!+a/3!+....n terms

Answers

Answered by prabhas24480
1

\huge\pink {\mathfrak{Hello!!!}}

-----------------------------------------------------------------------

{\huge{\overbrace{\underbrace{\purple{Your Answer:- }}}}}

_____________________________________________

Write a menu driven program

Explanation:

Function to calculate sum of following series:

1. S=1/4+1/8+1/12.........upto n terms

void series_first(int n)

{

 int i,x=4;

 double s=0;

 for(i=0;i< n;i++)

  {

  s=s+(double)1/x;

  x=x+4;

  }

  System.out.println("Result="+s);

 }

Function to calculate sum of following series:

2. S=1/1!-2/2!+3/3!.......upto n terms

void series_second(int n)

{

 int i;

 double s=0;

 int j,f;

 for(i=1;i<=n;i++)

  {

  f=1;

  for(j=2;j<=i;j++)

  f=f*j;

  s=s+(double)1/f;

  }

  System.out.println("Sum of the series="+s);

 }

Output

Enter value of n:

6

Enter choice (1 or 2):

2  

Sum of the series=1.7180555555555557

Refer the attachment ⤴️

Attachments:
Similar questions