Program for Armstrong Number in C

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

DURGESH

I Love python, so I like machine learning a Lot and on the other hand, I like building apps and fun games I post blogs on my website for Tech enthusiast to learn and Share Information With The World.

Leave a Reply

Your email address will not be published. Required fields are marked *

one × one =

Recent Content