Advertisement
idastan97

CSCI151 L16 P2

Sep 27th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. /*
  2.  * prog.c
  3.  *
  4.  *  Created on: 23 сент. 2016 г.
  5.  *      Author: Админ
  6.  */
  7. #include <stdio.h>
  8. #include <math.h>
  9.  
  10. double expApprox(double x, int n){
  11.     int i, k;
  12.     int p=1;
  13.     double s=0;
  14.     for (i=1; i<=n; i=i+2){
  15.         if (i==1) p=i;
  16.         else p*=((i-1)*i);
  17.         k=pow(-1,i/2);
  18.         s+=(k*pow(x,i)/p);
  19.     }
  20.     return s;
  21. }
  22. int main(){
  23.     int n;
  24.     double x;
  25.     scanf("%lf %i", &x, &n);
  26.     printf("%f", expApprox(x, n));
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement