In this C# tutorial we "check whether the entered number is Armstrong Number or not" . Here we are taking three variables "n" for number ,"rem" for remainder and "sum" for sum of digits respectively. Now, lets get started!!
Note: A number is armstrong if the sum of cubes of individual digits of a number is equal to the number itself. For example 371 is an armstrong number as 33 + 73 + 13 = 371. Some other armstrong numbers are: 0, 1, 153, 370, 407.
Note: A number is armstrong if the sum of cubes of individual digits of a number is equal to the number itself. For example 371 is an armstrong number as 33 + 73 + 13 = 371. Some other armstrong numbers are: 0, 1, 153, 370, 407.
using System; class arms { public static void Main(String []args) { int n, rem, sum = 0; Console.Write("Enter a Number : "); n = int.Parse(Console.ReadLine()); for (int i = n; i > 0; i = i / 10) { rem = i % 10; sum = sum + rem*rem*rem; } if (sum == n) { Console.Write("Entered Number is an Armstrong Number."); } else Console.Write("Entered Number is not an Armstrong Number."); } }
0 comments:
Post a Comment