Advertisement
nguyenhappy92

Nhập n chẵn, tính S(x,n) = x^2 + x^4 + ... + x^n

Sep 18th, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. // tinh S(x,n) = x^2 + x^4 + ... + 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. if(i%2==0)
  27. {
  28. T=T*x;
  29. M=M+T;
  30. }
  31. }
  32. printf("%ld",M);
  33. }
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement