pages:
- 1
BECCA SAYS
For those who getting WA. Just write the code for this problem and accept it :)
Description
A simple mathematical formula for e is
e=?0<=i<=n1/i!
where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small
values of n.
Input
No input
Output
Output the approximations of e generated by the above formula for the values of n from 0 to 9. The beginning of
your output should appear similar to that shown below.
Sample Input
no input
Sample Output
n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333
...
Daneshvar Amrollahi SAYS
Hi. Can anyone tell me why am I getting WA? This is my code:
#include<iostream>
#include<iomanip>
using namespace std;
unsigned long long int fact(int n)
{
if (n==0)
return 1;
else
return n*fact(n-1);
}
int main()
{
int n;
double ans;
cout<<1<<endl<<2<<endl<<2.5<<endl;
for (int k=3;k<=9;k++)
{
ans = 0;
for (int i=0;i<=k;i++)
ans+=(1/double(fact(i)));
cout<<fixed<<setprecision(9)<<ans<<endl;
}
return 0;
}
Daneshvar Amrollahi SAYS
・BECCA can make 1==3 anyway said:
For those who getting WA. Just write the code for this problem and accept it :)
Description A simple mathematical formula for e is e=?0<=i<=n1/i! where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n. Input No input Output Output the approximations of e generated by the above formula for the values of n from 0 to 9. The beginning of your output should appear similar to that shown below. Sample Input no input Sample Output n e - ----------- 0 1 1 2 2 2.5 3 2.666666667 4 2.708333333 ...
・BECCA can make 1==3 anyway said:
For those who getting WA. Just write the code for this problem and accept it :)
Description A simple mathematical formula for e is e=?0<=i<=n1/i! where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n. Input No input Output Output the approximations of e generated by the above formula for the values of n from 0 to 9. The beginning of your output should appear similar to that shown below. Sample Input no input Sample Output n e - ----------- 0 1 1 2 2 2.5 3 2.666666667 4 2.708333333 ...
Can you tell me why is this wrong?
cout<<"1"<<endl;
cout<<"2"<<endl;
cout<<"2.5"<<endl;
cout<<"2.666666667"<<endl;
cout<<"2.708333333"<<endl;
cout<<"2.716666667"<<endl;
cout<<"2.718055556"<<endl;
cout<<"2.718253968"<<endl;
cout<<"2.71827877"<<endl;
cout<<"2.718281526";
BECCA SAYS
Hello!
No.
Your output should exactly look like this:
cout << "n e" << endl;
cout << "- -----------" << endl;
cout << "0 1" << endl;
cout << "1 2" << endl;
cout << "2 2.5" << endl;
cout << "3 2.666666667" << endl;
cout << "4 2.708333333" << endl;
cout << "5 2.716666667" << endl;
cout << "6 2.718055556" << endl;
cout << "7 2.718253968" << endl;
cout << "8 2.718278770" << endl;
cout << "9 2.718281526" << endl;
Daneshvar Amrollahi SAYS
・BECCA can make 1==3 anyway said:
Hello!
No.
Your output should exactly look like this:
cout << "n e" << endl; cout << "- -----------" << endl; cout << "0 1" << endl; cout << "1 2" << endl; cout << "2 2.5" << endl; cout << "3 2.666666667" << endl; cout << "4 2.708333333" << endl; cout << "5 2.716666667" << endl; cout << "6 2.718055556" << endl; cout << "7 2.718253968" << endl; cout << "8 2.718278770" << endl; cout << "9 2.718281526" << endl;
The problem did not say anything about this kind of output! Thanks. It worked.
Login please!
In order to post something you must login first. You can use the form in the top of this page.