# 24 – Best C program to check Armstrong number

Table of Contents

## C program to check Armstrong number

C program to check Armstrong number : If number is equal to sum of all digits where each digit is raise to the count of digits then it is Armstrong number e.g. 153, 370, 371.

Let’s take 371

total digits is 371 (n) = 3

then 33 x 73 x 13 = 371

`#include <stdio.h>#include <math.h>void isArmstrong(int n){    int a = n, b = n, len = 0, rsl = 0, rem;    while(b!=0)    {        len++;        b/=10;    }    while(a!=0)    {        rem = a%10;        rsl += pow(rem,len);        a /= 10;    }    if(rsl == n)    {        printf("Yes!!! It is an Armstrong number");    }    else    {        printf("No!!! It is not an Armstrong number");    }}//itvoyagers.inint main (){    int x;    printf("Enter any number : ");    scanf("%d",&x);    isArmstrong(x);    return 0;}`

Output :

Enter any number : 371
Yes!!! It is an Armstrong number

———————————–

Enter any number : 1634
Yes!!! It is an Armstrong number

### Connect with us on following platforms

We are aiming to explain all concepts of C in easiest terms as possible.
ITVoyagers
Author