• Lenguaje

    Visual Basic .Net

  • 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
Module SerieParaObtenerSeno

    Sub Main()
        Dim i, n As Integer
        Dim exponente, factorial, sen_x, termino, x As Double
        sen_x = 0
        Console.Write("Ingresa el valor de x: ")
        x = Double.Parse(Console.ReadLine())
        Console.Write("Ingresa el valor de n: ")
        n = Integer.Parse(Console.ReadLine())
        For i = 1 To n
            Console.WriteLine("PROCESO " & i)
            If i = 1 Then
                exponente=1
                factorial=x
                termino=x
            Else
                exponente=exponente+2
                factorial=factorial*x*x
                termino=Math.Pow(x,exponente)/factorial
            End If
            If i Mod 2 = 0 Then
                sen_x=sen_x-termino
            Else
                sen_x=sen_x+termino
            End If
            Console.WriteLine("Valor de exponente: " & exponente)
            Console.WriteLine("Valor de factorial: " & factorial)
            Console.WriteLine("Valor de termino: " & termino)
            Console.WriteLine()
        Next i
        Console.WriteLine("Valor de sen x: " & sen_x)
        Shell ("cmd /c pause", AppWinStyle.NormalFocus, True)
    End Sub

End Module