title: I'm trying to swap first and last integer of an integer but when I input 1234 the output is 1351
body: <p>Edit:Im trying to swap first and Last integers</p>
  <p>When I input <code>1234</code> I can't get the output <code>4321</code> instead I get <code>1351</code>.<br />
  I checked if <code>digits</code> was 4 and <code>firstDigit</code> was 1, they both were correct but I'm not getting the output I want.</p>
  <p>Can you please help me?<br />
  Thanks.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  int main()
  {
      int firstDigit, lastDigit, digits = 0, number;
    
      printf(&quot;Input number \n&quot;);
      scanf(&quot;%d&quot;, &amp;number);
    
      firstDigit = number;
    
      do {
          firstDigit /= 10;  
      } while (firstDigit &gt; 9);
  
      digits = log10(number) + 1;
    
      lastDigit = number % 10;
    
      number = number - firstDigit * 10 * digits;
      number = number - lastDigit;
      number = number + lastDigit * 10 * digits;
      number = number + firstDigit; 
     
      printf(&quot;%d&quot;, number);
    
      return 0;
  }
  </code></pre>
  <p><strong>Edit:</strong> fixed the problem thank you guys.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  int main()
  {
      int firstDigit, lastDigit, digits = 0, number;
    
      printf(&quot;Input number \n&quot;);
    
      scanf(&quot;%d&quot;, &amp;number);
    
      firstDigit = number;
    
      do
      {
          firstDigit /= 10;  
      }
      while (firstDigit &gt; 9);
  
      digits = log10(number);
      lastDigit = number % 10;
      number = number - firstDigit * pow(10, digits);
      number = number - lastDigit;
      number = number + lastDigit * pow(10, digits);
      number = number + firstDigit; 
     
      printf(&quot;%d&quot;, number);
      return 0;
  }
  </code></pre>