Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. double my_power(int base, int n) {
  4. double total = base;
  5. for (int i = 1; i < n; i++) {
  6. total *= base;
  7. }
  8. return total;
  9. }
  10.  
  11. double sum_sequence(int n) {
  12. double sum = 0.0;
  13. for (int i = 2*n; i > 0; i--) {
  14. double val = 1/my_power(i, i);
  15. if (i % 2 == 0) {
  16. sum -= val;
  17. } else {
  18. sum += val;
  19. }
  20. }
  21. return sum;
  22. }
  23.  
  24. int main(int argc, char* argv[]) {
  25. printf("Enter n: ");
  26. int n;
  27. scanf("%d", &n);
  28. printf("Sum sequence = %f\n", sum_sequence(n));
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement