nmlt

 avatar
NguyenAnhQuan
c_cpp
a year ago
367 B
2
Indexable
Never
double nps = float(1) / n;
    double aps = a - floor(a);
    double diff = 9999;
    double res = 0;


    for (int i = 0; i <= n; i++)
    {
    	//std::cout << fabs((nps * i)) << "\n";
    	if (fabs((nps * i) - aps) < diff)
    	{
    		diff = fabs((nps * i) - aps);
    		res = floor(a) + (nps * i);

    	}
    }

   std::cout.precision(10);
   std::cout << res;