How to solve for an unknown upper bound in a summation I've always wondered: if you have something like 
$$
\sum\limits_{k=0}^x k
$$
And you want to find x such that the value of the summation is the closest to a constant c, how would you proceed?
And is the summation is, in general,
$$
\sum\limits_{k=a}^{a+x} f(k)
$$
Is there anyway to proceed?

There are cases for which it is "simple". Let us consider the case where $f(k)$ is a polynomial of $k$ $$f(k)=a_0+a_1 k+a_2 k^2+a_3 k^3+\cdots$$ So, $$S=\sum\limits_{k=a}^{a+x} f(k)=a_0 \sum\limits_{k=a}^{a+x} 1+a_1 \sum\limits_{k=a}^{a+x} k+a_2 \sum\limits_{k=a}^{a+x} k^2+a_3 \sum\limits_{k=a}^{a+x} k^3+\cdots$$ and the differents sums are successively $$x+1$$ $$\frac{1}{2} (x+1) (2 a+x)$$ $$\frac{1}{6} (x+1) \left(6 a^2+6 a x+2 x^2+x\right)$$ $$\frac{1}{4} (x+1) (2 a+x) \left(2 a^2+2 a x+x^2+x\right)$$ So, you are left with an explicit polynomial equation in $x$ ... to be solved; the easiest way (at least to me) should be to use algebra and text the closest integer value.
Suppose that $$f(k)=\sin(\alpha k+\beta)$$ Trigonometric manipulations would lead to another equation to solve for $x$ $$S=\sum\limits_{k=a}^{a+x} f(k)=\csc \left(\frac{\alpha }{2}\right) \sin \left(\frac{1}{2} \alpha  (x+1)\right) \sin
   \left(a \alpha +\beta +\frac{\alpha  x}{2}\right)$$
Suppose that $$f(k)=\cosh(\alpha k+\beta)$$ Similarly, we should obtain $$S=\sum\limits_{k=a}^{a+x} f(k)=\text{csch}\left(\frac{\alpha }{2}\right) \sinh \left(\frac{1}{2} \alpha 
   (x+1)\right) \cosh \left(a \alpha +\beta +\frac{\alpha  x}{2}\right)$$
Suppose that $$f(k)=e^{\alpha k+\beta}$$ Similarly, we should obtain $$S=\sum\limits_{k=a}^{a+x} f(k)=\frac{\left(e^{\alpha +\alpha  x}-1\right) e^{a \alpha +\beta }}{e^{\alpha }-1}$$
