• Lenguaje

    Java usando Scanner

  • Descripción

    Obtener el seno de un ángulo, la cual está dada por la función:
    Sen x = (x - x³/3! + x⁵5/5! - x⁷/7! + ...)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.Scanner;

public class SerieParaObtenerSeno {

    public static void main(String[] args) {
        int i, n;
        double exponente, factorial, sen_x, termino, x;
        sen_x = 0;
        System.out.print("Ingresa el valor de x: ");
        x = in.nextDouble();
        in.nextLine();
        System.out.print("Ingresa el valor de n: ");
        n = in.nextInt();
        in.nextLine();
        for (i=1; i<=n; i++) {
            System.out.print("PROCESO " + i);
            if(i==1)
            {
                exponente=1;
                factorial=x;
                termino=x;
            }
            else
            {
                exponente=exponente+2;
                factorial=factorial*x*x;
                termino=Math.pow(x,exponente)/factorial;
            }
            if(i%2==0)
                sen_x=sen_x-termino;
            else
                sen_x=sen_x+termino;
            System.out.println("Valor de exponente: " + exponente);
            System.out.println("Valor de factorial: " + factorial);
            System.out.println("Valor de termino: " + termino);
            System.out.println();
        }
        System.out.println("Valor de sen x: " + sen_x);
    }

}