C Program to check a number is armstrong or not using function


In this program, You will learn how to check a number is armstrong or not using function in c.


Some list of armstrong numbers is: 153, 370, 371, 407


Example: How to check a number is armstrong or not using function in c

Run it Now
#include<stdio.h>

int check(int n) {
   int r, arm = 0;

   while (n > 0) {
       r = n % 10;
       arm = arm + r * r * r;
       n = n / 10;
   }
   return arm;
}

int main() {

   int n, arm;

   printf("Enter a Number :");
   scanf("%d", &n);

   arm = check(n);

   if (arm == n) {
       printf("\nThe Number is ArmStrong :%d", n);
   } else {
       printf("\nThe Number is Not ArmStrong :%d", n);
   }

   return 0;
}

Output:

Enter a Number :153
The Number is ArmStrong :153