Write your question here.
hiiii everyone! so im making this program which calculates out the taylor series for e and i was able to do it however it went up to 2.71828 then stopped. i wanted the program to print out a longer decimal! so i tried to use double (all variables were originally float) to add length but when i did the program didnt calculate the number right! please help.
float main() Violates standard, should not compile. If your compiler allows that, I suggest to change it immideatly.
also printf_s is non-standard and I have no Idea how it is behave. If it is like normal printf(), you probably need to increase precision. Look there to see format string specifiers: http://en.cppreference.com/w/cpp/io/c/fprintf
example how it will look using C++ streams:
1 2 3
#include <iomanip>
//...
std::cout << setprecision(15) << e << std::endl;
well i always used float main cuz i thought int main would return an integer but i recently found out i was wrong. anyway im using microsoft visual studio and it always told me to use printf/scanf as printf_s/scanf_s.
and that didnt work as im using #include <stdio.h> not #include <iostream.h> which is what i thin cout and all that is apart of. got a stdio.h form of that line?
%d is for int parameters, not for double. Save yourself some trouble and use C++ streams.
You should note that log2(1/21!) < -65, meaning that even with double precision (64 bits), continuing iteration past that point will not add any more digits to the result.
it always told me to use printf/scanf as printf_s/scanf_s. Nobody could compile your code aside from those using visual studio.
And which version of VS do you use? If something older than 2012, upgrade. Also look documentation and turn on most warnings aside from "using standard function instead of Microsoft ones" aka "Warning: it looks like you might write portable code"
/sarcasm off
I have already posted link to printf format string description. Read it.
Also in C++ it is <cstdio> instead of outdated and unsupported <stdio.h>
and <cmath>. Also conio.h is extremely outdated and do not advised to use in any operation system newer than DOS (for which it was created).
i was able to add more digits by doing this
#include <cstdio>
#include <cmath>
#include <conio.h>
using namespace std;
long double fact(long double a){
int i;
long double b;
b=a;
for(i=1;i<b;i++){
a*=i;
}
return a;
}
int main(){
long double e=0;
int i;
for(i=1;i<1000;i++){
e+=1/(long double (fact(i)));
}
e+=1;
printf("%3.13Lf\n",e);
getch();
}
but it only goes out a certain length then only returns zeros
and what should i use intsead of conio.h? i use it cuz i saw it on the internet somewhere and it was the only way i could get my program to not quickly end before i could see it