import java.util.Scanner;
public class SerieTaylorEx {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Digite o valor de x:");
double x = scanner.nextDouble();
System.out.println("Digite o número de termos n:");
int n = scanner.nextInt();
double resultado = 0.0;
for (int i = 0; i < n; i++) {
resultado += Math.pow(x, i) / fatorial(i);
}
System.out.println("A aproximação de e^" + x + " usando " + n + " termos é: " + resultado);
}
// Método para calcular o fatorial de um número
public static long fatorial(int num) {
if (num == 0) {
return 1;
}
long fatorial = 1;
for (int i = 1; i <= num; i++) {
fatorial *= i;
}
return fatorial;
}
}
To embed this program on your website, copy the following code and paste it into your website's HTML: