Coding capital sigma notation

222 Views Asked by At

I cannot find a way to code the following formula. My goal is to have a single function into which I can input the values. The context of this calculation is to return the number of possible upDown permutations of n-numbers. Without using bruteforce and checking each permutation, i can simply compute this sum:
formula
My code at the moment is this:

int e(int i, int n)
{
    if (n == 0)
        return (0);
    else
        return (combinations(n, i)*e(n, i)*e(n, n-i));
}

int main(int argc, char *argv[])
{
    int n, sum = 0;
    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        sum = sum + combinations(n, i)*e(n, i)*e(n, n-i);
    }
    return (0);
}
0

There are 0 best solutions below