A number is called an Armstrong Number or Narcissistic number if the sum of its own digits raised to the power of the number of digits equals to the number. For example, 371 = 3^3 + 7^3 + 1^3 = 27 + 343 + 1 By logic, all single digit numbers are Armstrong numbers since n^1 = n. For a given number, we would need to find out if the given number is an Armstrong number or not.

```
public static bool IsArmstrongNumber(int n)
{
int r, cube, sum = 0, input = n;
if (n < 10)
return true;
while (n != 0)
{
r = n % 10;
cube = r * r * r;
sum = sum + cube;
n = n / 10;
}
return sum == input ? true : false;
}
```

**How it works:**

Calculating an Armstrong number relies on the same basic Divisibility rule of 10, on which the logic to count the number of digits can also be made.

For each iteration till the number is made 0, we strip the number of its last digit by modulus dividing with 10 and then cube the remainder and add it up to a total sum. Finally once the number is completely dealt, we check if the total sum is equal to the input number or not. If equal, it is an Armstrong number else not.

Special Numbers Loops • Added 2 months ago

Find if the given number is a Perfect Number

Special Numbers
Loops

Find if the given number is a Palindrome

Special Numbers
Loops

Find if the given number is an Armstrong Number

Special Numbers
Loops

Find if the given number is a Perfect Square

Special Numbers
Loops

Find all the Fibonacci numbers for a given limit

Special Numbers
Loops

Find the number of occurrences of a given character in a string

Strings
Loops

Find the reverse of given number

Loops

Find the Factorial of a given number using Recursion

Recursion
Loops

Check if a given string is Palindrome

Strings
Loops

Find if the given number is a Perfect Number

Special Numbers
Loops

Subscribe to my newsletter and get the first copy of every new post delivered straight into your inbox.

Externalizing Configurations to AWS SSM Parameter Store and using in ASP.NET Core API

AWS
ASP.NET Core

Working with Options pattern in ASP.NET Core - The Complete Guide

ASP.NET Core

Creating AWS Lambda Layers in ASP.NET Core - Getting started

AWS
ASP.NET Core

Deploying Express.js API to AWS Lambda and API Gateway

NodeJS
Express
MySql
AWS

Securing ASP.NET Core APIs with IdentityServer4 - Getting Started

ASP.NET Core
IdentityServer4