We will check if a given number is a palindrome or not using while loop.
In order to execute the code I’ve created a simple console application to print out the result.
Please find complete code below:
using System; namespace PracticeConsole { class Program { static void Main(string[] args) { Console.WriteLine("Please input any number and then hit enter:"); int myNumber = Convert.ToInt32(Console.ReadLine()); int temp, remainder, reverse = 0; temp = myNumber; bool isPalindrome = false; while (myNumber > 0) { remainder = myNumber % 10; reverse = reverse * 10 + remainder; myNumber /= 10; } if (temp == reverse) { isPalindrome = true; } else { isPalindrome = false; } Console.WriteLine(isPalindrome); Console.ReadLine(); } } }