This is a simple C# program to check whether entered number is Armstrong number or not. If you are a c# beginner or want to start learning the c# programming language, then this program will help you to understand the basics of c# programming. In this program, I will explain how to write a C# program to check Armstrong number.
Copy the below c# program and execute it in your Microsoft Visual Studio IDE (Integrated Development Environment ). At the end of this program, I have shared the output of program this program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
using System; public class ArmstrongProgram { public static void Main(string[] args) { int n,r,sum=0,temp; Console.Write("Enter any number to check armstrong number: "); n= int.Parse(Console.ReadLine()); temp=n; while(n>0) { r=n%10; sum=sum+(r*r*r); n=n/10; } if(temp==sum) { Console.Write("This number is a Armstrong Number."); } else { Console.Write("This number is not Armstrong Number."); } } } |
Enter any number to check armstrong number: 153
This number is a Armstrong Number.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: Armstrong number in c, armstrong number program in c#, c program, c program with output, c programs, c# program with example, c# tutorial for beginner