mihainan

Laboratorul 5 - Prob. 5

Nov 3rd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. /**
  2.  * Problema 5
  3.  * Laboratorul 5 - Seria CC
  4.  */
  5.  
  6. #include <stdio.h>
  7.  
  8. int factorial(int n)
  9. {
  10.     int p = 1, i;
  11.     for (i = 1; i <= n; i++)
  12.         p *= i;
  13.     return p;
  14. }
  15.  
  16. double putere(double x, int n)
  17. {
  18.     double p = 1;
  19.     int i;
  20.     for (i = 1; i <= n; i++)
  21.         p *= x;
  22.     return p;
  23. }
  24.  
  25. double taylor(double x, int n)
  26. {
  27.     double t = 1;
  28.     int i;
  29.     for (i = 1; i <= n; i++)
  30.         t += putere(x, i) / factorial(i);
  31.     return t;
  32. }
  33.  
  34. int main()
  35. {
  36.     float x;
  37.     int n;
  38.     printf("x = ");
  39.     scanf("%f", &x);
  40.     printf("n = ");
  41.     scanf("%d", &n);
  42.     printf("e ^ %.3f = %.3f\n", x, taylor(x, n));
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment