Solved programming problem

Solve Math Equation in C.

Source code

Your task is to mlculate the sum of the following series: 2/2^1 1!+2+4/2^2 2!+2+4+6/2^3 3!+.........+2+4+6+......+2n/2^n n!

 

#include<stdio.h>

#include<math.h>

int main()

{

    int n,i;

    int fact =1;

    printf("Please Enter Value: ");

    scanf("%d",&n);

    int a=0,p=0;

    for(i=1; i<=n*2; i++)

    {

        if(i%2==0)

        {

            a = a+i;

        }

    }

    for(i=1; i<=n; i++)

    {

        fact = fact *i;

    }

    double power = pow(2,n);

    double ans = a/(power*fact);

    printf("
Your Answer: %.2lf
",ans);

    return 0;

}

Output

Please Enter Value: 2

Your Answer: 0.75

Join the discussion

Add your comment