Advertisement
Guest User

Untitled

a guest
Oct 31st, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. DWORD ApproximateExampleThree(){
  2.     double stepSize = 0.0;
  3.     double tResult = 0.0;
  4.     double mResult = 10000.0;
  5.     double iterator = 10000.0;
  6.     double preciseValue = log(pow(10.0, -6))/(-1.0/500.0);
  7.  
  8.     fflush(stdin);
  9.     _tprintf(_T("Approximating equation [m' = -(m/V)*v], where V = 1000 m^3, v = 2 m^3/s.\n"));
  10.     _tprintf(_T("Please enter size of the step [#.#]: "));
  11.     _tscanf(_T("%lf"), &stepSize);
  12.    
  13.     if(stepSize <= 0){
  14.         _tprintf(_T("Size of the step can't be zero or negative! Aborting... \n"));
  15.         return ERROR_INVALID_PARAMETER;
  16.     }
  17.  
  18.     for(iterator; iterator > 1.0/100.0; iterator -= stepSize){
  19.         tResult = tResult + stepSize;
  20.         mResult = mResult + stepSize*(-mResult/500.0);
  21.     }
  22.  
  23.     _tprintf(_T("\nPrecise result is: %.10f seconds.\n"), preciseValue);
  24.     _tprintf(_T("Approximate result is: %.10f seconds\n"), mResult);
  25.     _tprintf(_T("Approximation error is: %.2f%%"), (fabs(preciseValue - mResult)/fabs(preciseValue))*100);
  26.  
  27.     return ERROR_SUCCESS;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement