Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- double my_power(int base, int n) {
- double total = base;
- for (int i = 1; i < n; i++) {
- total *= base;
- }
- return total;
- }
- double sum_sequence(int n) {
- double sum = 0.0;
- for (int i = 2*n; i > 0; i--) {
- double val = 1/my_power(i, i);
- if (i % 2 == 0) {
- sum -= val;
- } else {
- sum += val;
- }
- }
- return sum;
- }
- int main(int argc, char* argv[]) {
- printf("Enter n: ");
- int n;
- scanf("%d", &n);
- printf("Sum sequence = %f\n", sum_sequence(n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement