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:


69 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. This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.

    rpa Training in Chennai

    rpa Training in bangalore

    rpa Training in pune

    blueprism Training in Chennai

    blueprism Training in bangalore

    blueprism Training in pune

    iot-training-in-chennai

    ReplyDelete
  22. I am definitely enjoying your website. You definitely have some great insight and great stories. 

    java training in chennai | java training in bangalore

    java online training | java training in pune

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

    ReplyDelete
  24. 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
  25. 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
  26. Well you use a hard way for publishing, you could find much easier one!
    Blueprism training in tambaram

    Blueprism training in annanagar

    ReplyDelete
  27. 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
  28. 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
  29. 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 with Us pmp training Chennai | pmp training centers in Chennai | pmp training institutes in Chennai | pmp training and certification in Chennai | pmp training in velachery

    ReplyDelete
  30. 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
  31. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
    Microsoft Azure online training
    Selenium online training
    Java online training
    Python online training
    uipath online training

    ReplyDelete
  32. nice
    Web Designing Course in Hyderabad,ameerpet
    http://www.argiatechnologies.com

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

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

    ReplyDelete
  35. Your info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
    If you are looking for any Data science Related information please visit our website data science institutes in bangalore page!

    ReplyDelete
  36. Your info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
    If you are looking for any Data science Related information please visit our website data science institutes in bangalore page!

    ReplyDelete
  37. keep up the good work. this is an Assam post. this to helpful, i have reading here all post. i am impressed. thank you. this is our digital marketing training center. This is an online certificate course
    digital marketing training in bangalore | https://www.excelr.com/digital-marketing-training-in-bangalore

    ReplyDelete
  38. Nice information, valuable and excellent in Job, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.
    mobile phone repair in Canton
    iphone repair in Canton
    cell phone repair in Canton
    tablet repair in Canton
    ipad repair in Canton
    phone repair in Canton
    mobile phone repair canton
    iphone repair canton
    cell phone repair canton
    phone repair canton

    ReplyDelete
  39. I am overwhelmed by your post with such a nice topic. Usually I visit your blogs and get updated through the information you include but today’s blog would be the most appreciable. Well done!
    ExcelR Solutions

    ReplyDelete
  40. 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


  41. 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
  42. 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
  43. Thanks for taking the time to discuss this, I feel strongly about it and adore finding out additional on this topic.
    If feasible, as you acquire expertise, would you thoughts updating your blog with much more details? It is extremely useful for me.
    buy bitcoin instant

    ReplyDelete
  44. 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
  45. Wonderful blog found to be very impressive to come across such an awesome blog. I should really appreciate the blogger for the efforts they have put in to develop such an amazing content for all the curious readers who are very keen of being updated across every corner. Ultimately, this is an awesome experience for the readers. Anyways, thanks a lot and keep sharing the content in future too.
    Digital Marketing Training

    ReplyDelete
  46. Extraordinary blog went amazed with the content that they have developed in a very descriptive manner. This type of content surely ensures the participants to explore themselves. Hope you deliver the same near the future as well. Gratitude to the blogger for the efforts.

    Data Science Training

    ReplyDelete
  47. Stupendous blog huge applause to the blogger and hoping you to come up with such an extraordinary content in future. Surely, this post will inspire many aspirants who are very keen in gaining the knowledge. Expecting many more contents with lot more curiosity further.

    Data Science Certification in Bhilai

    ReplyDelete
  48. Learn Amazon Web Services for excellent job opportunities from Infycle Technologies, the Excellent AWS Training in Chennai. Infycle Technologies gives the most trustworthy AWS course in Chennai, with full hands-on practical training from professional trainers in the field. Along with that, the placement interviews will be arranged for the candidates, so that, they can meet the job interviews without missing them. To transform your career to the next level, call 7502633633 to Infycle Technologies and grab a free demo to know more

    ReplyDelete