Wednesday 23 April 2014

C# program to check whether a number is Armstrong or not

Armstrong :

Also known as narcissistic numbers, Armstrong numbers are the sum of their own digits to the power of the number of digits. As that is a slightly brief wording, let me give an example:
153 = 1³ + 5³ + 3³
Each digit is raised to the power three because 153 has three digits.


SOURCE CODE :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace palindrome
{
    class pali
    {
        public void palindrome()
        {
         int n, num, rev = 0, dig;
    
    
     Console.WriteLine("ENTER A NUMBER...: ");
     num = int.Parse(Console.ReadLine());
    
            n = num;
     while(num>0)
     {
          dig = num % 10;
          rev = rev * 10 + dig;
          num = num / 10;
     }
     if (n == rev)
          Console.WriteLine(" GIVEN NUMBER IS A PALINDROME");
     else
           Console.WriteLine(" GIVEN NUMBER NOT A PALINDROME");
     Console.Read();
        }
    }



    class Program
    {
        static void Main(string[] args)
        {
            pali p = new pali();
            p.palindrome();
        }
    }
}




OUTPUT:
ENTER A NUMBER
1231

 GIVEN NUMBER NOT A PALINDROME 

No comments:
Write comments

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2022