Computer Science, asked by shauryabist01, 5 months ago

Write a menu-driven program to find and display the result of the following series, based on the user's choice. (Paste the program below) *

Attachments:

Answers

Answered by anindyaadhikari13
2

Question:-

Write a menu-driven program to find and display the result of the following series, based on the user's choice.

Program:-

This is written in Java.

import java.util.*;

class Series

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the value of x: ");

double x=sc.nextInt();

System.out.print("Enter the value of n: ");

int n=sc.nextInt();

System.out.println("Enter 1 for series 1 sum and 2 for series 2 sum. ");

int ch=sc.nextInt();

double s=0.0;

switch(ch)

{

case 1:

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

s+=1/Math.pow(x, i);

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

break;

case 2:

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

s+=Math.sqrt(Math.pow(x,i))/i;

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

break;

default:

System.out.println("Invalid Choice. ");

}

}

}

Similar questions