fork download
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. double f(double & x)
  5. {
  6. if(x < 1)
  7. return 2*x;
  8.  
  9. return x*x;
  10. }
  11.  
  12. int main()
  13. {
  14. double const x_min = -5.0;
  15. double const x_max = 2.0;
  16. double const dx = 0.1;
  17.  
  18. double x = x_min;
  19.  
  20. std::cout.precision(20);
  21. while(x < x_max)
  22. {
  23. std::cout << x << "\t" << f(x) << std::endl;
  24. x += dx;
  25. }
  26. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
-5	-10
-4.9000000000000003553	-9.8000000000000007105
-4.8000000000000007105	-9.6000000000000014211
-4.7000000000000010658	-9.4000000000000021316
-4.6000000000000014211	-9.2000000000000028422
-4.5000000000000017764	-9.0000000000000035527
-4.4000000000000021316	-8.8000000000000042633
-4.3000000000000024869	-8.6000000000000049738
-4.2000000000000028422	-8.4000000000000056843
-4.1000000000000031974	-8.2000000000000063949
-4.0000000000000035527	-8.0000000000000071054
-3.9000000000000034639	-7.8000000000000069278
-3.8000000000000033751	-7.6000000000000067502
-3.7000000000000032863	-7.4000000000000065725
-3.6000000000000031974	-7.2000000000000063949
-3.5000000000000031086	-7.0000000000000062172
-3.4000000000000030198	-6.8000000000000060396
-3.300000000000002931	-6.600000000000005862
-3.2000000000000028422	-6.4000000000000056843
-3.1000000000000027534	-6.2000000000000055067
-3.0000000000000026645	-6.0000000000000053291
-2.9000000000000025757	-5.8000000000000051514
-2.8000000000000024869	-5.6000000000000049738
-2.7000000000000023981	-5.4000000000000047962
-2.6000000000000023093	-5.2000000000000046185
-2.5000000000000022204	-5.0000000000000044409
-2.4000000000000021316	-4.8000000000000042633
-2.3000000000000020428	-4.6000000000000040856
-2.200000000000001954	-4.400000000000003908
-2.1000000000000018652	-4.2000000000000037303
-2.0000000000000017764	-4.0000000000000035527
-1.9000000000000016875	-3.8000000000000033751
-1.8000000000000015987	-3.6000000000000031974
-1.7000000000000015099	-3.4000000000000030198
-1.6000000000000014211	-3.2000000000000028422
-1.5000000000000013323	-3.0000000000000026645
-1.4000000000000012434	-2.8000000000000024869
-1.3000000000000011546	-2.6000000000000023093
-1.2000000000000010658	-2.4000000000000021316
-1.100000000000000977	-2.200000000000001954
-1.0000000000000008882	-2.0000000000000017764
-0.90000000000000091038	-1.8000000000000018208
-0.80000000000000093259	-1.6000000000000018652
-0.70000000000000095479	-1.4000000000000019096
-0.600000000000000977	-1.200000000000001954
-0.5000000000000009992	-1.0000000000000019984
-0.40000000000000102141	-0.80000000000000204281
-0.30000000000000104361	-0.60000000000000208722
-0.20000000000000103806	-0.40000000000000207612
-0.10000000000000103251	-0.20000000000000206501
-1.0269562977782697999e-15	-2.0539125955565395998e-15
0.099999999999998978595	0.19999999999999795719
0.19999999999999898415	0.39999999999999796829
0.2999999999999989897	0.59999999999999797939
0.399999999999999023	0.79999999999999804601
0.4999999999999990008	0.9999999999999980016
0.59999999999999897859	1.1999999999999979572
0.69999999999999895639	1.3999999999999979128
0.79999999999999893419	1.5999999999999978684
0.89999999999999891198	1.799999999999997824
0.99999999999999888978	1.9999999999999977796
1.0999999999999989786	1.209999999999997522
1.1999999999999990674	1.4399999999999975042
1.2999999999999991562	1.6899999999999975042
1.399999999999999245	1.959999999999997744
1.4999999999999993339	2.2499999999999977796
1.5999999999999994227	2.5599999999999978328
1.6999999999999995115	2.8899999999999979039
1.7999999999999996003	3.2399999999999984368
1.8999999999999996891	3.6099999999999985434
1.999999999999999778	3.9999999999999986677