finding the last function

I need a Help Solving this problem...Listen i Am at the very beginner level. Som Pls forgive my mistakes..

1
2
3
4
5

sum(2^i.i!)

it should be like this: 2^1! + 2^2.2! + 2^3.3! + ........+ 2^n.n!

.. I am almost solved..but cannot make the last function that will add all those values upto my input..i am pasting my code..pls let me help findind the last step and explain


#include <stdio.h>
#include <conio.h>

int factorial(int i);
int power( int base, int exp );

main()
{
int n,i,b=2,s=0,multiply;
long int x;
scanf("%d", &i);
for (n=1;n<=i;n++)
{
s=((int) factorial(n));
}

multiply = s*power( b, i );
printf ("The Factorial of %d is\t : %d\n2 to The Power of %d is\t : %d\n(Factorial x Exponent) is : %d\nThe Sum of multiplication is : %d ",i, s,i, power( b, i ), multiply);
getch();
}

int factorial(int i)
{
if (i<=1)
return(1);
else
i=i*factorial(i-1);
return(i);
}
int power( int base, int exp )
{
int i, p = 1;
for( i = 1; i <= exp; i++ )
{
p *= base;
}
return p;
}
The code doesn't look like your algorithm. You have all the pieces, but it's all put together incorrectly I think.

Given: 2^1! + 2^2.2! + 2^3.3! + ........+ 2^n.n!

I take that to be:
1
2
3
    Sum of:
        2 ^ (i * i!)
    where i goes from 1 to n


Which can translate to:
1
2
3
    int sum = 0;
    for (int i = 1; i <= n; ++i)
        sum += each term


I've not filled in the term, but I hope this points you in the right direction.
Last edited on
Topic archived. No new replies allowed.