Check If
Entered Number Is Armstrong Or Not In C#
What is an Armstrong Number?
371 =
(3*3*3)+(7*7*7)+(1*1*1) where: (3*3*3)=27 (7*7*7)=343 (1*1*1)=1 So: 27+343+1=371 |
private static void
NumberArmstrong() { int
number, rem, temp, sum = 0;
Console.Write("Enter Your Number To Check :: ");
number = int.Parse(Console.ReadLine()); temp
= number; while
(number > 0) {
rem = number % 10;
sum = sum + (rem * rem * rem); number = number / 10; } if (temp
== sum)
Console.WriteLine(temp + " Is A Armstrong
Number"); else
Console.WriteLine(temp + " Is Not A Armstrong
Number");
Console.ReadKey(); } |
EmoticonEmoticon