1. ## The number e

How could i print the number E to the 50th digit, currently it is only printing to the 7th digit. here is my code

Code:
```#include <stdio.h>
#define MAX 30

int factorial ( int i ) ;
int main ( void )

{
double e ;
int i , j ;

for (e= 1 , i =1 ; i < MAX ; i++)
e += 1.0/(j=factorial(i));

printf("%f \n ",e);
return 0;
}

int factorial(int num)
{

if (num == 1)
return 1;
else
return num * factorial(num-1);
}```
if i make the variable e to a long double i get 0.0000000 and if I increase the MAX to lets say 40 i get inf .

btw. i am using gcc 3.3.3 on fedora 2
thanks 2. Code:
`printf("%.30f \n", e);`
However IIRC the factoral of 30 is much too large to fit inside of an int. 3. >How could i print the number E to the 50th digit
You use an arbitrary precision math library or do it manually. C doesn't natively support numeric quantities that long. 4. Prelude how do you do it manually?? 5. >Prelude how do you do it manually??
There are a number of ways, but usually they involve arrays or lists of either characters representing each digit with functions that manually perform mathematical operations on each digit, or integers where each integer marks a certain length of the total number. There was a contest not too long ago here that asked for something similar. If you ask nicely I'm sure some of the contestants would be happy to share their code and techniques with you.  6. thanks Prelude I will do a search on this website to track down the post. 7. Ok I found this code at http://remus.rutgers.edu/~rhoads/Code/e.c but i could barely understand the last 3 lines could someone help me.

Code:
```
int a , b=3301 , *c=a ,d , e , f ;

main()	{
for(e=b;--e;*c++=1); 			/* the loop sets all elements in array a to 1 */
*c=2;					/* last element of array a is equal to 2     */
for(d=2001;d--;printf("%05d",f))
for(c=a,e=b;e;f/=e--)
{ f+=*c*1e5 ; *c++=f%e; }
}```
thanks 8. Despite being poorly written (probably an attempt at obfuscation), it's pretty straightforward. Try tracing the program line by line until it's done. Then you'll have a good idea of how it goes about the calculations, from there you shouldn't have a problem figuring out what each one does.  9. Hey, one stuff... Why using recursion with a single way cicle??
Code:
```int factorial(int num)
{

if (num == 1)
return 1;
else
return num * factorial(num-1);
}```
I know this is pretty neat code, which one can find in any crapy recursion tutorial, but you could write to make it more eficient (remember that there are stack pointers).
Code:
```int factorial(int num){
int ac=1;
while(num>1)
ac*=num--;
return ac;
}```
Cheers. Popular pages Recent additions 