Armstrong Number using C#


An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. 
For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            int number, remainder, sum = 0;
            Console.Write("enter the Number");
            number = int.Parse(Console.ReadLine());
            for (int i = number; i > 0; i = i / 10)
            {
                remainder = i % 10;
                sum = sum + remainder*remainder*remainder;
 
            }
            if (sum == number)
            {
                Console.Write("Entered Number is an Armstrong Number");
            }
            else
                Console.Write("Entered Number is not an Armstrong Number");
                Console.ReadLine();
        }
     }
  }

Share this

Latest
Previous
Next Post »

2 comments

comments
Anonymous
June 27, 2019 at 3:41 AM delete

Hello Sandeep,
Thank you for sharing this article. ZetPDF is a .net SDK for adding PDF render and print support in .net applications. It is designed to solve most developer’s needs with regards to PDF rendering. Get in touch today so that we can help you.

Reply
avatar
October 23, 2024 at 12:07 AM delete

This is very good content you share on this blog. it's very informative and provide me future related information.
testing-tools-training-in-hyderabad

Reply
avatar