Factorial

I wrote a factorial function and it is working perfect :)
But only for the numbers until 65. I want it to be able to calculate even bigger numbers (like 100 or 1000). I maximized the size of value that the function is returning... Any ideas? Maybe storing it in array (tho I got no idea how :/ )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #include <iostream>
#include <conio.h>

using namespace std;

unsigned long long int Factorial(int x);

int main()
{
    int a;
    cout << "Input a number! ._.\n";
    cin >> a;
    cout << Factorial(a) << "\n";
    getch();
    return 0;
}

unsigned long long int Factorial(int x)
{
     if(x > 1) return x * Factorial(x - 1);
     else return x;
}


And three additional questions...

What two pointers pointing at each other can do?
Can I make a pointer pointing at itself (if yes, what can it do?)?
And keywords private, explicit, friend (I understand classes).

Thank you! :) \n
your factorial function does not have a default return value. One of your return statements cannot depend on a condition, so choose one of them and use that as the default return value.

1
2
3
4
int w = 2;
int *ptr1 = &w//2
int *ptr2 = ptr1;//2
ptr1 = ptr2;//2 
Er... How does that answer my question?

My code is correct, I am sure in that :)
I just want an answer for bigger numbers, much bigger.
If you want larger values, you might want to look into getting a biginteger library.

See the second code in this link:
http://www.cplusplus.com/forum/general/93643/#msg502709
I don't want to use any libraries beside iostream, fstream and conio.h (maybe algorithm and iomanip).
Well if you want larger values, either write it in python or any scripting languages or wait until c++ has support for big integer types.

Or make one...I believe someone made a fully functioning one written in c++ a while ago on this forum. If only I can find it...

Found this also:
http://www.cplusplus.com/forum/general/95596/#msg513774

He took down the links, but you can pm him for it (be nice :) )
Last edited on
Topic archived. No new replies allowed.