Advertisement
nguyenhappy92

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

Sep 18th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. //Tính S(x,n) = x + x^2 + x^3 + ... + x^n
  2. // khai bao thu vien
  3. #include<stdio.h>
  4. #include<conio.h>
  5.  
  6. void main()
  7. {
  8. // khai bao bien
  9. int n,x;
  10. // nhap du lieu
  11. scanf("%d%d",&n,&x);
  12. long T=1;
  13. long M=0;
  14. if(x==0&&n==0)
  15. printf("Khong xac dinh");
  16. else
  17. {
  18. if(x==0)
  19. {
  20. printf("0"); // xuat ra gia tri 0
  21. }
  22. else
  23. {
  24. for(int i=1;i<=n;i++)
  25. {
  26. T=T*x;
  27. M=M+T;
  28. }
  29. }
  30. printf("%ld",M);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement