Program for Armstrong Number in C

Here you will get the program for Armstrong number in C.

Armstrong number is n digits number whose entirety of digits raised to control n is equivalent to itself.

For example:

#include<stdio.h>
#include<math.h>
 
int main()
{
	int n,m=0,p=0,x,y;
	printf("Enter any number: ");
	scanf("%d",&n);
 
	y=n;
	
	while(y!=0){
		y=y/10;
		p++;
	}
	
	y=n;
	
	while(n!=0)
	{
		x=n%10;
		m+=pow(x,p);
		n=n/10;
	}
	
	if(y==m)
		printf("The given number is an armstrong number");
	else
		printf("The given number is not an armstrong number");
 
	return 0;
}

Output

Enter any number: 371
The given number is an armstrong number

Leave a Comment

error: Alert: Content is protected!!