Enter the Number : 371 Entered Number is an Armstrong Number
Users Online
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Latest Articles
Articles Hierarchy
C# Program to Check Armstrong Number
C# Program to Check Armstrong Number
This is a C# Program to check whether the entered number is an armstrong number or not.
This C# Program Checks Whether the Entered Number is an Armstrong Number or Not.
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.
Here is source code of the C# Program to Check Whether the Entered Number is an Armstrong Number or Not. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Check Whether the Entered Number is an Armstrong Number or Not */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication6 { 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(); } } }
In this C# program, we are reading the number using ‘i’ integer variable. If condition statement is used to check the number is even and odd. For even number the modulus of the value of ‘i’ variable by 2 is equal to zero, if the condition is true then print the statement as even number.
Otherwise, if the condition is false then execute the else statement, for odd number the modulus of the value of ‘i’ variable by 2 is not equal to zero, if the condition is true then execute the statement and print the statement as odd number.