Advertisement
nguyenhappy92

Tính S(x,n) = x + (x^2)/2! + (x^3)/3! + ... + (x^n)/n!

Sep 18th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. //Tính S(x,n) = x + (x^2)/2! + (x^3)/3! + ... + (x^n)/n!
  2. // Khai bao ham thu vien
  3. #include<stdio.h>
  4. #include<conio.h>
  5. long tinhtu(int x,int n);
  6. long tinhmau(int n);
  7. void main()
  8. {
  9. // nhap du lieu
  10. int x,n;
  11. //
  12. scanf("%d%d",&x,&n);
  13. double s=0;
  14. for(int i=1;i<=n;i++)
  15. {
  16. s=s+ (double)tinhtu(x,i)/(tinhmau(i));
  17. }
  18. printf("%.2lf",s);
  19. }
  20. long tinhmau(int n)
  21. {
  22. long s=1;
  23. if(n==0|| n==1)
  24. {
  25. return 1;
  26. }
  27. else
  28. {
  29. for(int i=2;i<=n;i++)
  30. {
  31. s=s*i;
  32. }
  33. return s;
  34. }
  35. }
  36. long tinhtu(int x,int n)
  37. {
  38. long t=1;
  39. if(x==0)
  40. return 0;
  41. else
  42. {
  43. for(int i=1;i<=n;i++)
  44. {
  45. t=t*x;
  46. }
  47. return t;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement