Check the given number is palindrome or not. when ever we use moduler that means we pick the number and store in any one valiable.when ever we use the devide symbol that mean we remove number from the given number and store another valiable.

here i used console application . requrement like 1)enter number new readline and enter next check condition for palindrome

Palindrome means read the same backword or forwardsresult should same as given by user. in this blog i given the input as interger. if we reverse it, the result should same as the input of given number.

for example i given 151 as input and stores in number variable.

next it goes in to while loop. then we need reminder logic is reminder =number %10,

the result stores in reminder. next statement executes and give result in number logic is number = number/10.

here one right side number deleted remaining number stores in number. next statement executes and gives the result is sum, logic is sum* 10+reminder. like that the loop executes give the result in temp varible. next we take the if condition checks the number equals to temp then it is a palindrome else not palindrome

using System;

class Program

{

static void Main(string[] args)

{

int number, reminder, sum = 0, temp;

//clrscr();

Console.WriteLine("\n --Check The given Number is Palindrome or not <<<< ");

Console.Write("\n Enter Number: ");

number = Convert.ToInt32(Console.ReadLine());

temp = number;

while (number > 0)

{

reminder = number % 10; // pick number from remainder

number = number / 10; // remopve number from quotient

sum = sum * 10 + reminder;

}

Console.WriteLine("\n The Reversed Number = \n", sum);

if (temp == sum)

{

Console.WriteLine("\n The Number is Palindrome \n\n");

} else {

Console.WriteLine("\n The Number is not a palindrome \n\n");

}

Console.ReadLine();

}

}

## No comments:

Post a Comment