Monday, 20 February 2017

palindrome number or not program in c# using while loop

frequently asking logical program in interviews for dotnet fresher

//Palindrome number or not program in c# using while loop
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication86
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, rem, rev = 0, temp;
            Console.WriteLine("enter a no to be reverse");
            n = int.Parse(Console.ReadLine());
            temp = n;
            while (n > 0)
            {
                rem = n % 10;
                rev = rev * 10 + rem;
                n = n / 10;

            }
            Console.WriteLine("Given number is = {0}", temp);
            Console.WriteLine("Its reverse is  = {0}", rev);
            if (temp == rev)
            {

                Console.WriteLine("the no is palindrome");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("the no not a palindrome no");
            }
        }
    }
}

Output Screenshot:





No comments:

Post a Comment