title: Finding out whether a number is a palindrome or not in C#
body: <p>I am new to C# and was doing this program as an exercise. I have managed to get my program to print the reversed number of the input given by the user, but when I move onto checking whether it is a palindrome or not, it does not calculate the answer correctly. It always prints 'not a palindrome'. </p>
  
  <p>After some error checking, I realized that the reason why it was doing this is because the last number that gets stored in <code>newnum</code> is just the last digit after being reversed and not the entire number. How can I rectify this??</p>
  
  <p><em><strong>My Code</em></strong></p>
  
  <pre><code>        int i, remainder = 0, newnum = 0;
          Console.WriteLine("Enter a Number: ");
          int uinput = Convert.ToInt32((Console.ReadLine()));
          for (i = uinput; i &gt; 0; i = (i / 10))
          {
              remainder = i % 10;
              Console.Write(remainder);
  
              newnum = remainder;
  
          }
  
  
          if (newnum == uinput)
          {
              Console.WriteLine("The Number {0} is a palindrome", uinput);
          }
          else
          {
              Console.WriteLine("Number is not a palidrome");
          }
          Console.WriteLine(uinput);
          Console.WriteLine(newnum);
          Console.ReadKey();
      }
  </code></pre>
  
  <p>I also looked online at another code example, but the thing I don't understand in that is why num is being converted to boolean type in the while loop? Is that just to keep the loop running?</p>
  
  <p><em><strong>The Code reffered to above</em></strong></p>
  
  <pre><code>        int num, rem, sum = 0, temp;
          //clrscr();
          Console.WriteLine("\n &gt;&gt;&gt;&gt; To Find a Number is Palindrome or not &lt;&lt;&lt;&lt; ");
          Console.Write("\n Enter a number: ");
          num = Convert.ToInt32(Console.ReadLine());
          temp = num;
          while (Convert.ToBoolean(num))
          {
              rem = num % 10;  //for getting remainder by dividing with 10
              num = num / 10; //for getting quotient by dividing with 10
              sum = sum * 10 + rem; /*multiplying the sum with 10 and adding
                         remainder*/
          }
          Console.WriteLine("\n The Reversed Number is: {0} \n", sum);
          if (temp == sum) //checking whether the reversed number is equal to entered number
          {
              Console.WriteLine("\n Number is Palindrome \n\n");
          }
          else
          {
              Console.WriteLine("\n Number is not a palindrome \n\n");
          }
          Console.ReadLine();
  </code></pre>
  
  <p>Any sort of help is much appreciated!! Thank You :)</p>