# C program to check a number is Armstrong or not

## C program to check a number is Armstrong or not

This page has a C program to check a number is Armstrong or not. The Armstrong number is an integer number. Armstrong Number is also called as Narcissistic number or Pluperfect digital invariant. Three digit Armstrong number must be equal to the sum of cubes of all digits of the 3 digit number. n-digits Armstrong number must be equal to the sum of nth power of all digits of the n-digits number. For Example . . . 153 and 1634 are Armstrong numbers. That is, 1*1*1*+5*5*5+3*3*3 = 153,  1*1*1*1+6*6*6*6+3*3*3*3+4*4*4*4=1634 are Armstrong numbers. We can write the programs in many ways to find whether a number belongs to Armstrong or not. In this webpage I have used three techniques to find whether the given number belongs to Armstrong or not. The below given C program is used to check whether a given number is Armstrong number or not. Kindly check out the program to find whether the given number belongs to Armstrong or not. The Armstrong or not program can be asked in different ways for school and college going students.

### Program to check an Armstrong number

#include<stdio.h>
int main(){
int numb,rem,sum=0,entr,nr,i,m=1,digits=0;
int initial,final;
clrscr();
printf("\n Give any Integer number: \n");

scanf("%d",&numb);
entr = numb;
nr=numb;
while(nr>0){
nr = nr / 10;
digits +=1;
}
nr=numb;
while(nr!=0){
rem = nr % 10;
nr = nr / 10;
for(i=1;i<=digits;i++){
m = m*rem;
}
sum +=m;
m=1;
}
if(sum == entr)
printf("\n The given Number  %d is Armstrong ",entr);

else

printf("\n The given Number  %d is not Armstrong Number",entr);
return 0;
}

Sample output:

Give any Integer number:  153

The given Number  153  is Armstrong

Give any Integer number:  5674

The given Number  5674  is not Armstrong Number

### Program to check any Armstrong number using function

#include<stdio.h>
int armstrong(int);
int main(){
int numb,sum,entr;
clrscr();
printf("\n Give any Integer number: \n");
scanf("%d",&numb);
entr = numb;
sum = armstrong(numb);
if(sum == entr)
printf("\n The given Number %d is Armstrong ",entr);
else
printf("\n The given Number %d is not Armstrong Number",entr);
getch();
return 0;
}

int armstrong(int n){
int nr, digits=0, i, rem, s=0, m=1;
nr=n;
while(nr>0){
nr = nr / 10;
digits +=1;
}
nr=n;
while(nr!=0){
rem = nr % 10;
nr = nr / 10;
for(i=1;i<=digits;i++){
m = m*rem;
}
s +=m;
m=1;
}
return(s);
}

Sample output:

Give any Integer number:  153

The given Number  153  is Armstrong

Give any Integer number:  6074

The given Number  6074  is not Armstrong Number

### Program to check a 3 digit Armstrong Number

#include<stdio.h>

int main(){

int numb,rem,sum=0,entr;

printf("\n Enter a three digit integer number: \n");

scanf("%d",&numb);

entr = numb;

while(numb!=0){

rem=numb%10;

numb=numb/10;

sum=sum+(rem*rem*rem);

}

if(sum==entr)

printf("\n %d is an Armstrong number",entr);

else

printf("\n %d is not an Armstrong number",entr);

return 0;

}

Sample output:

Enter a three digit integer number: 153

153 is an Armstrong number

## Most Related Armstrong or not Programs in C

About Er. T.Tharesh Kumar

I am a Professor and Head of Department of Computer Science in an Arts and Science College. I have designed this website to provide solved example programs of different categories for all the school and college going students to learn C language deeply, and to practice Interview based Multiple Choice (Objective Type) questions and answers.

## Armstrong numbers can be checkd by C program

The Armstrong is an integer number, and it has no decimal point. It is clear that, the n-digits Armstrong number must be equal to the sum of nth power of all digits of the n-digits number. For Example . . .  the integer numbers such as 153 and 1634 are Armstrong numbers. The Armstrong numbers can be checkd as 1*1*1 + 5*5*5 + 3*3*3 = 153,  1*1*1*1 + 6*6*6*6 + 3*3*3*3 + 4*4*4*4 = 1634. The Armstrong numbers can be checkd by the above C program.