Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #define e 2.71828
- #define RELATIVEERROR 0.0005
- #define LIMIT 10000
- using namespace std;
- int main()
- {
- int index = -1;
- for(int i=1; i<LIMIT; i++){
- double product = i * e;
- double error = fabs(round(product) - product) / e;
- cout << i << " " << product << " " << error << endl;
- if(error <= RELATIVEERROR){
- index = i;
- break;
- }
- }
- // I have found the appropriate index, if this exists
- if(index == -1){
- cout << "I cannot find a good approach of e (relativeError <= 0.05%) with integers in the range of " << LIMIT << endl;
- }
- else{
- cout << "A good approach of e (relativeError <= 0.05%) with integers in range of " << LIMIT << " is: " << round(index * e) << " / " << index << " = " << round(index * e) / index << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement