Computer Science, asked by manpreetsingh264mk, 10 months ago

Please do question 19 part 3 series in blue j java

Attachments:

Answers

Answered by rkk123
1

Explanation:

import java.util.*;

import java.lang.Math;

public class Program

{

public static int factorial(int num){

int i = 1, fact = 1;

while(i <= num)

{

fact *= i;

i++;

}

return fact;

}

public static int fn(int x, int n){

int sum = 0, tmp = 1;

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

sum += ((int)Math.pow(x, i)/factorial(tmp));

tmp += 2;

}

return sum;

}

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("enter the value for n: ");

int x = in.nextInt();

int n = in.nextInt();

System.out.println(fn(x, n));

}

}

Similar questions