help please

hey anyone has an idea about calculate serie
like this :
1+.......x!/x^y
x&Y input integer always positive
May be you'll find some answers here http://www.cplusplus.com/reference/cmath/?
Or what is your problem more precisely?
The factorial can only be computed manually, no ready function to use.
1
2
3
4
int factorial=1,y,x;
cin>>x;
for (int i=x;i>1;i--)
       factorial=factorial*i;

The xy can be computed using the function pow().
see the link provided by tcs it'll help a lot.
Note that coder1's factorial calculation will only be accurate when x is a positive integer less than or equal to 12 on many platforms, given the limited range of values that an int can hold.

EDIT: Using an unsigned long long with MS Visual C++ 2010's compiler bought me enough room to get accurately to 20!

http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.100%29.aspx
Last edited on
closed account (3qX21hU5)
The factorial can only be computed manually, no ready function to use.

If by this you mean there is no function in the STL I believe you are correct, but if you mean you can't have a function that find a factorial you are not correct. You can find a factorial pretty easy by using recursion. I believe there might also be one in the boost library also but I'm not sure.

1
2
3
4
unsigned long factorial(unsigned long i)
{
    return (i == 1 || i == 0) ? 1 : factorial(i - 1) * i;
}


Anyways there is a quick function for you to show how you can calculate a factorial with recursion.
Last edited on
Often when calculating the sum of a series, it isn't necessary to calculate the complete factorial each time. Usually, there is a simple relationship between successive terms of the series. Just one or two multiplications or divisions are sufficient to derive each term from the previous one.


An example would be in this thread:
http://www.cplusplus.com/forum/beginner/96114/

I don't know whether the original question in this thread is intended to use that particular series - superficially it is different, but I'm wondering whether there is an error in the question?
Last edited on
If by this you mean there is no function in the STL I believe you are correct, but if you mean you can't have a function that find a factorial you are not correct.

yes, in STL i mean.
the code i wrote can be easily made as a function.
Topic archived. No new replies allowed.