Question

In: Computer Science

Fill in the following function to sum the series of 1 + x/1 + x^2/2 +...

Fill in the following function to sum the series of 1 + x/1 + x^2/2 + x^3/3 + .. + x^n/n using Java Program

Solutions

Expert Solution

Please find your solution below and if any doubt or need change comment.and do upvote .

CODE:

import java.util.Scanner;
public class Main
{
    //rturns the sum of the series
    public static double sumTheSeries(int x,int n){
        double i,sum=1.0;
        double product=x;
        //find sum till n 
        for( i=1;i<=n;i++){
            sum=sum+product/i;
            product=product*x;
        }
        return sum;
    }
        public static void main(String[] args) {
          Scanner sc=new Scanner(System.in);
          //take user input
          System.out.print("Enter value of x: ");
          int x=sc.nextInt();
          System.out.print("Enter value of n: ");
          int n=sc.nextInt();
          System.out.printf("The summation is: %.2f", sumTheSeries(x,n));
        }
}

OUTPUT:


Related Solutions

1) Write an algorithm to calculate the sum of the following series: Sum =x-x3/3! + x5/5!...
1) Write an algorithm to calculate the sum of the following series: Sum =x-x3/3! + x5/5! – x7/7! +……. Stop when the term<0.0001. 2) An internet service provider charges its subscribers per month as follows: Data usage (n), in gbs charges (NIS) 0.0<n<=1.0 250 1.0<n<=2.0 500 2.0<n<=5.0 1000 5.0<n<=10.0 1500 n>10 2000 Write a C program to read the usage(n) from a file and print the charges to be paid by the subscribers. Your program must include the function calculate...
C-coding Question1: Fill in the function body for the provided sum() function such that the call...
C-coding Question1: Fill in the function body for the provided sum() function such that the call sum(g, i, j) returns the value of the calculation: Note: For the case where j < i, the function sum() should return 0. #include <stdio.h> int g(int val) { return val * val; } int sum(int (*f)(int val), int start, int end) { /* Your code goes here */ } int main() { printf("Result: %d\n", sum(g, 10, 20)); return 0; } ****************************************************** Question 2:...
Write a complete program to sum the following series: (hint: use the for loop) 1 /2...
Write a complete program to sum the following series: (hint: use the for loop) 1 /2 + 1/ 4 + 1 /6 + ⋯ + 1 /100 PS: use C++ language please
-Write a program in C++: • to find the sum of the series 1! /1+2! /2+3!...
-Write a program in C++: • to find the sum of the series 1! /1+2! /2+3! /3+4! /4+5! /5 using the function1, • to convert decimal number to binary number using the function2, • to check whether a number is a prime number or not using the function3, • to check whether two given strings are an anagram using the function4. important must do in (Multi-Filing) of c++
Determine the sum of the series ∑n=1∞ ( 6n)/(n+2) if possible. (If the series diverges, enter...
Determine the sum of the series ∑n=1∞ ( 6n)/(n+2) if possible. (If the series diverges, enter 'infinity', '-infinity' or 'dne' as appropriate.)
1) Find the Taylor series (to second order terms) of the function f(x,y) = x^2 −4x...
1) Find the Taylor series (to second order terms) of the function f(x,y) = x^2 −4x + y + 9 around the point x = 3, y = −1. 2)Explain why the corresponding Taylor Series (to third order terms) will be the same as the second-order series.
1.)is the function f (x) = x exp^ (-x ^ 2/2) a proper function of the...
1.)is the function f (x) = x exp^ (-x ^ 2/2) a proper function of the operator O= d2 / dx2-x2? if so, what is the intrinsic value? 2.)is the function f (x) = exp^ (4ix) -exp ^(-4ix) its own function of the operator d2 / dx2? if so, what is the intrinsic value? 3.)is the function f (x) = exp^ (2ix) -exp ^(-2ix) a proper function of the operator d^2 / dx^2? if so, what is the intrinsic value?...
Find the real Fourier series of the piece-wise continuous periodic function f(x)=1+x+x^2 -pi<x<pi
Find the real Fourier series of the piece-wise continuous periodic function f(x)=1+x+x^2 -pi<x<pi
Find the Fourier series of the following functions f(x) = sinx+x^2+x, −2 < x < 2
Find the Fourier series of the following functions f(x) = sinx+x^2+x, −2 < x < 2
using power series of 1/(1-x), a) derive the power series for 1/(9+x^2) and determine the radius...
using power series of 1/(1-x), a) derive the power series for 1/(9+x^2) and determine the radius of convergence of this power series b) use the result from (a) to derive the power series for tan^-1(x) and state the radius of convergence of this power series
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT