ProgIng - Programación en Ingeniería
Loading...
Searching...
No Matches
Ejemplo015.c
Go to the documentation of this file.
1
32
33#include <stdio.h>
34
35int main(int argc, char *argv[])
36{
37 (void)argc;
38 (void)argv;
39
40 int n, i, j;
41 int signo;
42 float x;
43 float sx; /* acumulador */
44 float fct; /* término positivo: x^(2i+1)/(2i+1)! */
45
46 do {
47 printf("Ingrese el numero de terminos: ");
48 scanf("%d", &n);
49 } while (n < 1);
50
51 printf("Ingrese el valor de x: ");
52 scanf("%f", &x);
53
54 for (i = 0, sx = 0; i < n; i++)
55 {
56 signo = 1 - 2*(i % 2); /* +1, -1, +1, -1... */
57
58 /*
59 fct = Π_{k=1}^{2i+1} (x/k)
60 Se implementa con j=0..2i:
61 multiplica x/(j+1)
62 */
63 for (j = 0, fct = 1; j < (2*i + 1); j++)
64 fct *= (x / (j + 1));
65
66 sx += (signo * fct);
67 }
68
69 printf("sen(%f) = %f\n", x, sx);
70 return 0;
71}
double fct(double x, int n)
Definition Ejemplo029.c:34
int main(void)
Definition Ejemplo_035.c:15