How do i get third digit from right of any given number in cpp?
<p>How can i get third digit of any given number like this </p>

<pre><code>           Input                                       Output
           1234567                                      5
           98765                                        7
</code></pre>

<p>I have tried this function</p>

<pre><code>char nthdigit(int x, int n)
{
    while (n--) {
        x /= 10;
    }
    return (x % 10) + '0';
}
</code></pre>

<p>But it did not work properly for me</p>