Answer to Question #218077 in C for Hemambar

Question #218077

Write a C program to solve the given series using recursion

1+(2^x)/2+(4^x)/4+(8^x)/8+...


1
Expert's answer
2021-07-22T06:46:10-0400
#include <stdio.h>
#include <math.h>


double series(double x, int n) {
    if ( n <= 0 )
        return 1;
    return series(x, n-2) + pow(n, x) / n;
}


int main() {
    double x, s;
    int n;
    
    printf("Enter x: ");
    scanf("%lg", &x);
    printf("Enter n: ");
    scanf("%d", &n);
    if (n%2 == 1) {
        printf("Error n must be even number\n");
        return 1;
    }
    s = series(x, n);
    printf("The series is %lg\n", s);
    return ;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS