Hello there Forum!
So, I'm new at programming C so my understanding about it is really rather limited. But I managed to put together a simple program to output factorials up to 100. It works fine until n!=18 but afterwards, when the numbers really are atronomical, only the few first digits of the output factorial are correct. The rest is replaced by 0's.
So, to 100! the output should be a 157 digit number with zeros for the last 24 digits, however, instead, the program returns a 157 digit number with zeros for the last 130 digits. Only the first 27 digits are correct.
What am I doing wrong?
Code:
#include<stdio.h>
int main(void){
int i;
double n;
n=1;
for(i=1;i<=100;i++){
n*=i;
printf("%.0f\n",n);}
system("pause");
return(0);
}
And also, I also made a program to output Euler's number, but I can only get it right up to 18 decimal places. How can I print about e to 100 decimal places?
Code:
#include<stdio.h>
int main(void){
int i;
float n,e,t;
n=1;
e=1;
for(i=1;i<=30;i++){
n*=i;
t=n;
e+=1/t;
printf("%.20f\n",e);}
system("pause");
return(0);
}