Q7 write a program to check the number is palindrome or not.
We know that palindrome number means if we reverse the number then it will same as entered as input. The code for this program is as follows:
Dim n, temp, rev As Integer
System.Console.Write("Enter Integer number = ")
n = System.Console.ReadLine()
temp = n
rev = 0
While (n > 0)
rev = rev * 10 + n Mod 10
n /= 10
If (rev = temp) Then
System.Console.Write("Number is pallindrome==" & rev)
System.Console.Write("Number is not pallindrome==" & rev)
In this program we have declared a variables n, re0, temp. Now we have used theConsole.Write function that shows message “Enter Integer Number =”; and when we enter any number then this number is read by Console.ReadLine function and assign to n variable.
Here we have assigned the value of n to the temp variable. Here we have used a while loop. Here we have used the condition n>0 means loop will be continued while the value of n variable is greater than 0. Inside the loop, first of all we have to calculate the remainder of the n; when we use n Mod 10 ; this will give the last digit of the number. After that we have used the rev*10+n Mod 10; here we add the value of remainder with rev*10 and assign to rev. now we have to get the next digit so that we have used the n/=10 and assign it to n. after that we have to check that the reversed number is equal to the original number. If reverse number is same as entered number then if part will be executed otherwise else block will be executed. The output is as follows: