Advertisement
nguyenhappy92

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

Sep 18th, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. // Tính S(x,n) = x + (x^2)/(1+2) + (x^3)/(1+2+3) + ... + (x^n)/(1+2+3+..+n)
  2. // Khai bao 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. int n,x;
  10. scanf("%d%d",&n,&x);
  11. double s=0;
  12. for (int i=1;i<=n;i++)
  13. {
  14. s=s+ (double)tinhtu(x,i)/tinhmau(i);
  15. }
  16. printf("%.2lf",s);
  17. }
  18. long tinhmau(int n)
  19. {
  20. long M=0;
  21. for(int i=1;i<=n;i++)
  22. {
  23. M=M+i;
  24. }
  25. return M;
  26. }
  27. long tinhtu(int x,int n)
  28. {
  29. long t=1;
  30. if(x==0)
  31. return 0;
  32. else
  33. {
  34.  
  35. for(int i=1;i<=n;i++)
  36. {
  37. t=t*x;
  38. }
  39. }
  40.  
  41. return t;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement