C Program to check a number is armstrong or not


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


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


Example: How to check a number is armstrong or not in C

Run it Now
#include<stdio.h>

int main() {

   int x, y, r, arm = 0;
   printf("Enter a Number :");
   scanf("%d", &x);

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

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

   return 0;
}

Output:

Enter a Number :153
The Number is Armstrong :153