Search This Blog

This website completely moved to new domain. For latest content, visit www.programmingposts.com

C# Program to find the Number Palindrome or not



C# Program to find whether the Number is Palindrome or not

using System;


namespace NumberPalindrome
{
    class Program
    {
        static void Main(string[] args)
        {
            int num, rem, sum = 0, temp;
            //clrscr();
            Console.WriteLine("\n >>>> To Find a Number is Palindrome or not <<<< ");
            Console.Write("\n Enter a number: ");
            num = Convert.ToInt32(Console.ReadLine());
            temp = num;
            while (num>0)
            {
                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();
        }
    }
}

Output 1:

 Output 2:


40 comments:

  1. // program to check if a string/number is a palindrome or not.
    using System;
    class Palindrome
    {
    public static bool CheckPal(Char[] MyStr)
    {
    int first = 0;
    int Last;
    Last = MyStr.Length - 1;//using Length method to check the total number of characters in the array.
    while (first < Last)//executes the loop till the last character of the array.
    {
    if (MyStr[first] == MyStr[Last])// checking if arrays from both the ends are equal.
    {
    first++;
    Last--;
    }
    else
    {
    return false;
    }
    }
    return true;
    }
    public static void Main(string[] args)
    {

    char[] str = new char[10];
    Console.WriteLine(" Enter a string/number to check if it is a palindrome \n");
    str = Console.ReadLine().ToCharArray();// accepting string and converting it to char array.
    Console.WriteLine(CheckPal(str));
    Console.ReadLine();
    }
    }









    ReplyDelete
  2. int pal = 1001;
    char[] number = pal.ToString().ToCharArray();
    int iteration = number.Count() / 2;
    int endChar = number.Count() - 1;
    bool isPalindromic = true;
    for (int i = 0; i < iteration; i++)
    {
    if (number[i] == number[endChar])
    {

    }
    else
    {
    isPalindromic = false;
    }
    if (!isPalindromic)
    {
    break;
    }
    endChar--;
    }
    Console.WriteLine(isPalindromic.ToString());
    Console.ReadLine();

    ReplyDelete
  3. int reminder, number, sum = 0;
    Console.WriteLine();
    number = int.Parse(Console.ReadLine());
    for (int i = number; i >0; i=i/10)
    {
    reminder = i % 10;
    sum = sum * 10 + reminder;
    }
    if (sum == number)
    {
    Console.WriteLine("Armstrong number ");
    }
    else
    {
    Console.WriteLine("not a Armstrong number ");
    }
    Console.ReadLine();

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. using System.Collections.Generic;
    public static LinkedList WagonLinkList = new LinkedList();

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. using System;

    public class Program
    {
    public static bool TruePalindrome(string word)
    {
    word=word.ToLower();
    bool result=false;
    string NewWord="";
    for(int start=(word.Length-1);start>=0;start--)
    {
    NewWord=NewWord+word[start];
    }
    if(word==NewWord)
    {
    return true;
    }
    return false;
    }

    public static void Main(string[] args)
    {
    Console.WriteLine(Palindrome.IsPalindrome("RAVAR"));
    }
    }

    ReplyDelete
  10. public static Tuple TowTotal(IList list, int sum)
    {
    for(int firstIndex=0;firstIndex<list.Count-1;firstIndex++)
    {
    for(int secondIndex=firstIndex+1;secondIndex<list.Count;secondIndex++)
    {
    if(list[firstIndex]+list[secondIndex]==sum)
    {
    return Tuple.Create(firstIndex,secondIndex);
    }
    }
    }
    return null;

    ReplyDelete
  11. int Capacity { get; set; }
    List Items = new List();
    Safe(int capacity)
    {
    this.Capacity = capacity;
    }
    int getCapacity()
    {
    return Capacity;

    }

    List getItems()
    {
    return Items;
    }
    void AddItem(string item)
    {
    if (Items.Count < Capacity)
    {
    Items.Add(item);
    Console.WriteLine(Items.Count + "" + "/" + "" + Capacity);
    }
    else
    {
    throw new Exception("Error Occured safe is full ");
    }
    }
    string getDescription()
    {
    if (Items.Count >= Capacity)
    return "Safe is full";
    else
    return "Safe: " + Items.Count + "/" + Capacity;
    }

    ReplyDelete
  12. if(Password.Length>=12)
    {
    int UpperCount = 0;
    int LowerCount = 0;
    int DigitCount = 0;
    //for(int start=0;start= 'a' && c <= 'z')
    {
    LowerCount++;
    }
    if (c >= 'A' && c <= 'Z')
    {
    UpperCount++;
    }

    if (c >= '0' && c <= '9')
    {
    DigitCount++;
    }
    }

    if (UpperCount > 0 && LowerCount > 0 && DigitCount > 0)
    {
    return true;
    }
    }
    return false;

    ReplyDelete
  13. using System.Collections.Generic;
    public static LinkedList WagonLinkList = new LinkedList();

    ReplyDelete
  14. public static int FrogWays(int n)
    {
    int firstnumber = 0, secondnumber = 1, result = 0;

    if (n == 1) return 1;
    if (n == 2) return 2;
    for (int i = 2; i <= n + 1; i++)
    {
    result = firstnumber + secondnumber;
    firstnumber = secondnumber;
    secondnumber = result;
    }
    return result;
    }

    ReplyDelete
  15. public static int MyCountNumbers(int[] sortedArray, int lessThan)
    {
    int Icount=0;
    foreach(int val in sortedArray)
    {
    if(val<lessThan)
    {
    Icount++;
    }
    else
    {
    return Icount;
    }
    }
    return Icount;
    }

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. public static int BestLongRunning(string str)
    {
    int bestIndex = 0, bestScore = 0, currIndex = 0;
    for (var i = 0; i < str.Length; ++i)
    {
    if (str[i] == str[currIndex])
    {
    if (bestScore < i - currIndex)
    {
    bestIndex = currIndex;
    bestScore = i - currIndex;
    }
    }
    else
    {
    currIndex = i;
    }
    }
    return bestIndex;

    ReplyDelete
  18. static int BoxNoIs(int products, int availableLargeBoxes, int availableSmallBoxes)
    {
    if (products < 5)
    return products;
    if ((products - (5 * availableLargeBoxes + availableSmallBoxes)) > 0)
    return -1;
    int rl = products / 5;
    if (rl > availableLargeBoxes)
    rl = availableLargeBoxes;
    return rl + (products - 5 * rl);
    }

    ReplyDelete
  19. class StacksBank
    {
    public int capacity { get; set; }
    public Stack Items = new Stack();
    Stacks(int MyCapacity)
    {
    capacity = MyCapacity;
    }
    int getCapacity()
    {
    return capacity;
    }
    List getItems()
    {
    return Items.ToList();
    }

    void addItem(string item)
    {
    if (Items.Count >= capacity)
    {
    throw new Exception ("OverFlow");
    }

    Items.Push(item);
    }

    string getDescription()
    {
    if (Items.Count >= capacity)
    return "Safe is full";
    else
    return "Safe: " + Items.Count + "/" + capacity;
    }

    ReplyDelete
  20. using System;

    namespace ChickenEgg
    {

    public interface IBird
    {
    Egg Lay();
    }

    public class Egg
    {
    private readonly Func _createBird;
    private bool _hatched;

    public Egg(Func createBird)
    {
    _createBird = createBird;
    }

    public IBird Hatch()
    {
    if (_hatched) throw new InvalidOperationException("Egg already hatched.");

    _hatched = true;
    return _createBird();
    }
    }

    public class Chicken : IBird
    {
    public Egg Lay()
    {
    var egg = new Egg(() => new Chicken());
    return egg;
    }
    }

    public class Program
    {
    public static void Main(string[] args)
    {
    var chicken1 = new Chicken();
    var egg = chicken1.Lay();
    var childChicken = egg.Hatch();
    var childChicken2 = egg.Hatch();
    }
    }

    }

    ReplyDelete
  21. It is nice article to improve my knowledge.thank you for sharing useful info
    web programming tutorial
    welookups

    ReplyDelete
  22. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    python training in rajajinagar
    Python training in btm
    Python training in usa
    Python training in marathahalli
    Python training in pune

    ReplyDelete
  23. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    Devops training in sholinganallur

    ReplyDelete
  24. Well you use a hard way for publishing, you could find much easier one!
    Blueprism training in tambaram

    Blueprism training in annanagar

    ReplyDelete
  25. Awesome! Education is the extreme motivation that open the new doors of data and material. So we always need to study around the things and the new part of educations with that we are not mindful.

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in btm

    ReplyDelete
  26. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.

    AWS Interview Questions And Answers

    AWS Training in Bangalore | Amazon Web Services Training in Bangalore

    AWS Training in Pune | Best Amazon Web Services Training in Pune

    Amazon Web Services Training in Pune | Best AWS Training in Pune

    AWS Online Training | Online AWS Certification Course - Gangboard

    ReplyDelete
  27. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  28. This comment has been removed by the author.

    ReplyDelete
  29. This comment has been removed by the author.

    ReplyDelete
  30. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    Big Data Hadoop Training In Chennai | Big Data Hadoop Training In anna nagar | Big Data Hadoop Training In omr | Big Data Hadoop Training In porur | Big Data Hadoop Training In tambaram | Big Data Hadoop Training In velachery


    ReplyDelete


  31. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it. The angular js programming language is very popular which are most widely used.



    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery














    ReplyDelete
  32. Mumbai University B.Com 2nd, 4th, 6th Sem Result 2020
    Osmania University B.Com 2nd, 4th, 6th Sem Result 2020
    Utkal University B.Com 2nd, 4th, 6th Sem Result 2020
    You’d outstanding guidelines there. I did a search about the field and identified that very likely the majority will agree with your web page.

    ReplyDelete
  33. Hey, Wow all the posts are very informative for the people who visit this site. Good work! We also have a Website. Please feel free to visit our site. Thank you for sharing.Well written article Thank You Sharing.DevOps Training in Chennai

    DevOps Course in Chennai


    ReplyDelete