Armstrong Number

Algorithm

Step 1: Start

Step 2: Declare integers n, t, t1, sum, sum1, count, digit

Step 3: Take input for number (n)

Step 4: Count the number of digits

Step 5: Compute sum of digits raised to power count

Step 6: Check if sum equals original number

Step 7: Print whether it is an Armstrong number or not

Step 8: End

Flowchart

graph TD; A([Start]) --> B[Declare variables]; B --> C[/Input n/]; C --> D[Count digits]; D --> E[Compute sum of digits^count]; E --> F{Sum = Original Number}; F -->|Yes| G[/Print - Armstrong Number/]; F --> |No| H[/Print - Not an Armstrong Number/]; G --> I([End]); H --> I; %% Define styles classDef start fill:#00cc44,stroke:#006622,stroke-width:2px,color:#ffffff; classDef stop fill:#ff4444,stroke:#cc0000,stroke-width:2px,color:#ffffff; classDef input_output fill:#ffdd44,stroke:#cc9900,stroke-width:2px,color:#000000; classDef process fill:#4488ff,stroke:#0044cc,stroke-width:2px,color:#ffffff; classDef decision fill:#ff8844,stroke:#cc4400,stroke-width:2px,color:#ffffff; %% Apply styles class A start; class I stop; class C,G,H input_output; class B,D,E process; class F decision;

Program

#include<stdio.h>
#include<math.h>
int main()
{
    int n, t, t1, sum = 0, sum1 = 0, count = 0, digit;
    printf("Enter a number :");
    scanf("%d", &n);
    
    t = n;
    t1 = n;
    while(n != 0)
    {
        digit = n % 10;
        sum = sum + digit;
        n = n / 10;
        count++;
    } 
    
    sum1 = 0; 
    while(t != 0)
    {
        digit = t % 10;
        sum1 = sum1 + pow(digit, count);
        t = t / 10;
    }
    
    printf("\n Number of digits in %d : %d", t1, count);
    printf("\n Sum of the digits of %d : %d", t1, sum);
    
    if(sum1 == t1)
    {
        printf("\n %d is an Armstrong Number", t1);
    }
    else
    {
        printf("\n %d is Not an Armstrong Number", t1);
    }
    return 0;
}
                

Test Case Output
Enter a number: 153

Number of digits in 153: 3
Sum of the digits of 153: 9
153 is an Armstrong Number