Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot calculate factorials bigger than 20! ! How to do so?
    primarykey
    data
    text
    <p>I am using unsigned long long integer format in order to calculate big factorials. However my code fails at some point can you have a look at it? Actually it is part of a larger code for Taylor expansion of exponential function, but that part is irrelevant at this point. I will appreciate any suggestions. </p> <p>Thanks</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;math.h&gt; //We need to write a factorial function beforehand, since we //have factorial in the denominators. //Remembering that factorials are defined for integers; it is //possible to define factorials of non-integer numbers using //Gamma Function but we will omit that. //We first declare the factorial function as follows: unsigned long long factorial (int); //Long long integer format only allows numbers in the order of 10^18 so //we shall use the sign bit in order to increase our range. //Now we define it, unsigned long long factorial(int n) { //Here s is the free parameter which is increased by one in each step and //pro is the initial product and by setting pro to be 0 we also cover the //case of zero factorial. int s = 1; unsigned long long pro = 1; if (n &lt; 0) printf("Factorial is not defined for a negative number \n"); else { while (n &gt;= s) { printf("%d \n", s); pro *= s; s++; printf("%llu \n", pro); } return pro; } } int main () { int x[12] = { 1, 5, 10, 15, 20, 100, -1, -5, -10, -20, -50, -100}; //Here an array named "calc" is defined to store //the values of x. unsigned long long k = factorial(25); printf("%llu \n", k); //int k; ////The upper index controls the accuracy of the Taylor Series, so ////it is suitable to make it an adjustable parameter. //int p = 500; //for ( k = 0; k &lt; p; k++); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload