
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Write a C# program to check if the entered number is Armstrong number?
A number is an Armstrong number if the sum of the cube of each digit of the number is equal to the number itself.
Here, we will find out the remainder and will sum it to the cube of remainder.
rem = i % 10; sum = sum + rem*rem*rem;
Then if the above sum that comes out after loop iteration is equal to the sum, then it will be an Armstrong number.
if (sum == num) { Console.Write("Armstrong Number!"); }
The following is an example −
Example
int num, rem, sum = 0; // checking for armstrong number num = 153; for (int i = num; i > 0; i = i / 10) { rem = i % 10; sum = sum + rem*rem*rem; } if (sum == num) { Console.Write("Armstrong Number!"); } else Console.Write("Not an Armstrong Number!"); Console.ReadLine();
- Related Articles
- C# Program to Check Whether the Entered Number is an Armstrong Number or Not
- C++ Program to Check Armstrong Number
- Python Program to Check Armstrong Number
- C Program to Check Armstrong Number?
- Java Program to Check Armstrong Number
- Swift Program to Check Armstrong Number
- Java program to check whether the given number is an Armstrong number
- Golang Program to Check For Armstrong Number
- Java Program to Check Armstrong Number between Two Integers
- Haskell program to check armstrong number between two integers
- Kotlin Program to Check Armstrong Number between Two Integers
- Write a C# program to check if a number is Palindrome or not
- Write a C# program to check if a number is divisible by 2
- Write a C# program to check if a number is prime or not
- Python Program to Check if a Number is a Perfect Number

Advertisements