Last Updated:

# C Program to check if a number is armstrong or not

## Algorithm

Input: Input a numbers
output: Check if a number is Armstrong or not

1. Start
2. Input a numbers say n
3. count =0
4. result=0
5. orginalnum = n
6. check = n
7. do
7.1 n/=10
7.2 count++
8. while n! = 0
9. while orginalnum ! = 0
9.1 rem = orginalnum % 10
9.2 result += pow (rem , count)
9.3 orginalnum /=10
10. if (result == check)
10.1 print 'check' is an Armstrong number
11. else
11.1 print 'check' is not an Armstrong number
12. stop

## C Program

#include<stdio.h>
#include<math.h>
int main( )
{
int n,count=0,orginalNum,rem,result=0,check;
printf("Enter a number to check Armstrong: ");
scanf("%d", &n);
orginalNum = n;
check = n;
do{
n/=10;
++count;
} while (n!=0);
while (orginalNum!=0) {
rem = orginalNum % 10;
result += pow(rem , count);
orginalNum /=10;
}
if (result == check) {
printf("%d is an Armstrong number.", check);
}
else {
printf("%d is not an Armstrong number.", check);
}
return 0;
}

Note: This Program was created using visual studio code. The Program file can be downloaded by clicking here