fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main() {
  7. cout <<setw(11)<< "original" << setw(10) <<"correct" <<setw(10) <<"wrong" <<endl;
  8. for (float N=0; N<1.5f; N+=0.1f) {
  9.  
  10. auto final = ((0.5*(pow(2,0.5))*(pow((pow(((N/2)-0.5),2)+pow((N/2)-0.5,2)),0.5)))-0.5)*4;
  11. auto final2 = 2*abs(N-1) - 2;
  12. auto final3 = 4 * (N / 2 - 1);
  13. cout <<setw(11)<< final << setw(10) <<final2 <<setw(10) <<final3 << (N>=1?"\tok":"\touch")<<endl;
  14. }
  15. return 0;
  16. }
Success #stdin #stdout 0s 4548KB
stdin
Standard input is empty
stdout
   original   correct     wrong
4.44089e-16         0        -4	ouch
       -0.2      -0.2      -3.8	ouch
       -0.4      -0.4      -3.6	ouch
       -0.6      -0.6      -3.4	ouch
       -0.8      -0.8      -3.2	ouch
         -1        -1        -3	ouch
       -1.2      -1.2      -2.8	ouch
       -1.4      -1.4      -2.6	ouch
       -1.6      -1.6      -2.4	ouch
       -1.8      -1.8      -2.2	ouch
         -2        -2        -2	ok
       -1.8      -1.8      -1.8	ok
       -1.6      -1.6      -1.6	ok
       -1.4      -1.4      -1.4	ok
       -1.2      -1.2      -1.2	ok