idastan97

CSCI151 L16 P1

Sep 27th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double expApprox(double x, int n){
  5.     int i;
  6.     int p=1;
  7.     double s=1;
  8.     for (i=1; i<=n; i++){
  9.         p*=i;
  10.         s+=(pow(x,i)/p);
  11.     }
  12.     return s;
  13. }
  14. int main(){
  15.     int n;
  16.     double x;
  17.     scanf("%lf %i", &x, &n);
  18.     printf("%f", expApprox(x, n));
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment