Interchanging the first and last digits of a number in C
<p>Interchanging the first and last digits of a number in C.
 I cracked the question using most basic knowledge of c.
 I haven't used any strings or arrays or bit-wise operator, just simple     logic. for clearer understanding take an example and see.    </p>

<pre><code>#include &lt;stdio.h&gt;

int main()
{
   int a,x,y,n=1,b;
   printf("enter no");
   scanf("%d",&amp;a);
   b=a;                //used further
   if(a&gt;0)
   {
      y=a%10;           //last digit
   }
   while(a&gt;0)
   {
      x=a%10;
      if(a&gt;0 &amp;&amp; a&lt;=9)
      {
         x=a;         //first digit
      }
      a=a/10;
      n=n*10;
   }
   n=n/10;
   printf("%d\n%d\n%d\n%d\n",b,n,x,y);  //just to confirm readings
   b=(b-y);  
   b=(b+x);  
   b=b-(x*n);   
   b=b+(y*n);  
   printf("%d",b);   
}
</code></pre>