Guys, I forgot my math. Faced a trivial task - it is necessary to express the dependence of y on x - f (x) = y through the formula, according to this data table:
2 answers
So?
double f(const double x) { return floor((x-1)/2+1); }
|
Of course, so:
int f(int x) { static const table[] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 }; if (x < 1 || x > 10) throw std::invalid_argument("x"); return table[x]; }
Your K. O.
You can, of course, int f(int x) { return (x + 1)/2; }
int f(int x) { return (x + 1)/2; }
, but this does not meet the requirements, since the behavior at the other points is not specified.
|