Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Problema 5
- * Laboratorul 5 - Seria CC
- */
- #include <stdio.h>
- int factorial(int n)
- {
- int p = 1, i;
- for (i = 1; i <= n; i++)
- p *= i;
- return p;
- }
- double putere(double x, int n)
- {
- double p = 1;
- int i;
- for (i = 1; i <= n; i++)
- p *= x;
- return p;
- }
- double taylor(double x, int n)
- {
- double t = 1;
- int i;
- for (i = 1; i <= n; i++)
- t += putere(x, i) / factorial(i);
- return t;
- }
- int main()
- {
- float x;
- int n;
- printf("x = ");
- scanf("%f", &x);
- printf("n = ");
- scanf("%d", &n);
- printf("e ^ %.3f = %.3f\n", x, taylor(x, n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment