Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. float serieseno (float, int);
  5. float factorial (int);
  6.  
  7.  
  8. void main (void){
  9. float x, y;
  10. int n;
  11.  
  12. printf("Inserte el valor de x:");
  13. scanf("%f", &x);
  14. printf("Cuantas cifras significativas quieres?:" );
  15. scanf("%i",&n);
  16.  
  17. y=serieseno(x,n);
  18.  
  19. printf(" el seno es %.16f",y);
  20.  
  21. }
  22.  
  23.  
  24. float serieseno (float x, int n){
  25. float ea=-1, y=0, es=0;
  26. float yant;
  27.  
  28. es= 0.5 * pow(10.0,2.0-n);
  29. ea = es + 1;
  30.  
  31. n = 0;
  32.  
  33. while(ea > es || n == 0){
  34. yant = y;
  35. y += pow(-1,n)/factorial(2 * n + 1) * pow(x,2 *n +1);
  36. n++;
  37. if (yant)
  38. ea = fabs( y-yant)/yant;
  39. }
  40.  
  41. return y ;
  42.  
  43. }
  44.  
  45.  
  46. float factorial (int n){
  47. float y=1;
  48.  
  49. while(n>1){
  50. y *= n;
  51. n--;
  52. }
  53. return y;
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement