Armstrong Number
// Armstrong Number
Console.WriteLine("Enter any Three digit number to know wheater is it Armstrong or not");
int a = int.Parse(Console.ReadLine());
int p;
int q;
int r = a;
int s;
while (a != 0)
{
p = a % 10;
a = a / 10;
while (a != 0)
{
q = a % 10;
a = a / 10;
s = (p * p * p) + (q * q * q) + (a * a * a);
if (r == s)
{
Console.WriteLine("It's a ArmStrong Number");
}
else
{
Console.WriteLine("It's not a ArmStrong Number");
}
break;
}
}
Console.ReadLine();
No comments:
Post a Comment