Method to find solutions for $\{nz\}\in (x,x+\epsilon)$ for an irrational value $z$. (approximation with the fractional part) Suppose that we are given an irrational number $z$, a value $x\in[0,1)$ and soe $\epsilon> 0$. We want to find an integer $n$ such that $\{nz\}\in (x,x+\epsilon)$ . (Note that by $\{\alpha\}$ I mean the fractional part of $\alpha$ in this context).
Such an $n$ clearly must exist as $\{nz\}$ is dense in $[0,1]$. But I have not been able to find a good method to come up with an $n$. I thought about putting $z$ as a periodic fraction but I am not sure how to proceed.
Some code in c or a similar language would be greatly appreciated.
 A: For a treatment without continued fractions, see Diophantine Approximations by Niven. 
Well, I did an example with $x + \frac{\epsilon}{2}= 1/2$ and $z=\pi.$ I wanted to get 
$$ n \pi - m - \frac{1}{2} = n \pi - \frac{2m+1}{2} $$ small, or
$$    \pi - \frac{2m+1}{2n} $$ very small.
The first convergent to $\pi$ with odd numerator and even denominator was 
$333/106,$ and we do get
$$ 53 \pi \approx 166.50441 $$
which is pretty good.
Needs work
A: By Dirichlet's approximation theorem for $\forall z \in \mathbb{R}$ and $\forall N \in \mathbb{N}$ there exist integers $p,q \in \mathbb{Z}$ such that $|q z - p| \lt \frac{1}{N}$. Integers $p,q$ can be derived from the convergents of the continued fraction of $z$.
It can be assumed WLOG that $0 \le q z - p \lt \frac{1}{N}\,$ (otherwise replace $q \mapsto -q\,$, $p \mapsto -p\,$), with the first inequality being strict when $z$ is irrational. Taking $N \gt \cfrac{1}{\epsilon}\,$ this gives $0 \lt \{qz\} = qz - p \lt \epsilon\,$.
With $k = \left\lceil \cfrac{x}{\{qz\}}\right\rceil$ it follows that $k \{qz\} \in (x,x+\{qz\}) \subseteq (x,x+\epsilon)\,$.
But $k \{qz\} = k(qz-p) = kqz - kp = \{kqz\}\,$, so in the end $\{nz\} \in (x,x+\epsilon)$ for $n = k q\,$.

[ EDIT ]  Below is a fully worked out example for $z = \varphi \simeq 1.618\dots$ with $x=0.5$ and $\epsilon=0.01\,$.


*

*The convergents of $\varphi$ are ratios of consecutive Fibonacci numbers, and the first one with denominator greater than $1 / \epsilon = 100$ is $\cfrac{p}{q}=\cfrac{233}{144}\,$.

*$144 \varphi -233=-0.003\dots \lt 0\,$, so we choose the opposites as $q,p$ i.e. $q=-144, p=-233\,$.

*$k = \left\lceil \cfrac{0.5}{-144 \varphi+233} \right\rceil = \left\lceil 160.998\dots \right\rceil = 161\,$.

*$n = kq = 161 \cdot (-144) = -23184$ and, indeed, $-23184 \varphi = -37512.499995\dots\,$, which has a fractional part of $\{-23184 \varphi\} = 0.5000048\dots \in (0.5, \,0.51)\,$.
Note #1: the above assumes that the fractional part is defined as $\{x\} = x - \lfloor x \rfloor\,$, including for negative numbers. In case of alternative definitions, the formula for $k$ would need to be adjusted.
Note #2: since the question was tagged as programming, too, it may be worth noting that this method gives an eligible, yet quite conservative $n\,$, usually a lot larger than the best (smallest) possible $n\,$. For example, working out the $z = \pi$ case this way yields $n = 57 \cdot 106 = 6042\,$, which is in fact correct, but far up from the $n=53$ shown in Will Jagy's answer.
