To check a given number is Armstrong or not using C


Levels of difficulty: / perform operation:

C program to check a given number is Armstrong or not. A number is said to be Armstrong if sum of the cube of the individual digit is equal to the number.

C Program

#include <stdio.h>
#include <conio.h>
void main()
{
	int num,num1,digit,arm=0;
	clrscr();
	printf("\nENTER A NUMBER: ");
	scanf("%d",&num);
	num1=num;
	do
        {
		digit=num%10;
		num=num/10;
		arm=arm+(digit*digit*digit);
	}
	while(num!=0);
	if(arm==num1)
		printf("\n%d IS AN AMSTORNG NUMBER",num1);
	else
		printf("\n%d IS NOT AN AMSTRONG NUMBER",num1);
	getch();
}


Output