Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Tính S(x,n) = x + (x^2)/(1+2) + (x^3)/(1+2+3) + ... + (x^n)/(1+2+3+..+n)
- // Khai bao thu vien
- #include<stdio.h>
- #include<conio.h>
- long tinhtu(int x,int n);
- long tinhmau(int n);
- void main()
- {
- int n,x;
- scanf("%d%d",&n,&x);
- double s=0;
- for (int i=1;i<=n;i++)
- {
- s=s+ (double)tinhtu(x,i)/tinhmau(i);
- }
- printf("%.2lf",s);
- }
- long tinhmau(int n)
- {
- long M=0;
- for(int i=1;i<=n;i++)
- {
- M=M+i;
- }
- return M;
- }
- long tinhtu(int x,int n)
- {
- long t=1;
- if(x==0)
- return 0;
- else
- {
- for(int i=1;i<=n;i++)
- {
- t=t*x;
- }
- }
- return t;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement