Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- float serieseno (float, int);
- float factorial (int);
- void main (void){
- float x, y;
- int n;
- printf("Inserte el valor de x:");
- scanf("%f", &x);
- printf("Cuantas cifras significativas quieres?:" );
- scanf("%i",&n);
- y=serieseno(x,n);
- printf(" el seno es %.16f",y);
- }
- float serieseno (float x, int n){
- float ea=-1, y=0, es=0;
- float yant;
- es= 0.5 * pow(10.0,2.0-n);
- ea = es + 1;
- n = 0;
- while(ea > es || n == 0){
- yant = y;
- y += pow(-1,n)/factorial(2 * n + 1) * pow(x,2 *n +1);
- n++;
- if (yant)
- ea = fabs( y-yant)/yant;
- }
- return y ;
- }
- float factorial (int n){
- float y=1;
- while(n>1){
- y *= n;
- n--;
- }
- return y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement