In this article check whether
the input number is Armstrong
no or not by using console
application in c#.net using while loop:
Step1: Take a new console application using c# as
a language in the Visual studio.
Step2: Declare the variables int_Number, int_Temp, int_Remainder, int_Sum and initialize the “int_sum”
value to 0.
Step3: Read an input from the User in this
Variable “int_Number” for storing that number which you want to test for Armstrong number,
now assign that value to “int_Temp”.
Step4: now run the while
loop till the value of “int_Temp” doesn’t become 0 and then digit by digit take
the values and multiply that digit value three times and then add it to the
“int_sum” variable and in the next step divide the “int_Temp” variable by 10. In the
end check if the “int_sum” value is equal to the “int_Number” then it means
that it is Armstrong number.
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
Armstrong_Number
{
class Program
{
static void Main(string[]
args)
{
int
int_Number, int_Temp, int_Remainder, int_Sum;
int_Sum = 0;
Console.WriteLine("please the numbers to be tested for Armstrong
number");
int_Number = int.Parse(Console.ReadLine());
int_Temp = int_Number;
while
(int_Temp != 0)
{
int_Remainder = int_Temp % 10;
int_Sum = int_Sum +
int_Remainder * int_Remainder * int_Remainder;
int_Temp = int_Temp / 10;
}
if
(int_Number == int_Sum)
{
Console.WriteLine("Entered number is an armstrong number. ");
}
else
{
Console.WriteLine("Entered number is not an armstrong number. ");
}
Console.ReadLine();
}
}
}
Output: