title: How to swap first and last digit in number in c++
body: <p>I don't understand why the following code always answers with <code>0</code>.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main() {
  
      int n,a,b;
      cin&gt;&gt;n;
      b=n%10;
  
      while(n!=0) {
          a=n%10;
          n=n/10;     
      }
      a=b;
      b=a;
      cout&lt;&lt;n&lt;&lt;endl;
      return 0;
  }
  </code></pre>