Armstrong Number:
- Three Digit Armstrong Number defined as the Sum of cubes of its Digit is equal to the Number Itself.
- Armstrong Number is also known as Narcissistic Number.
- Example: 153 = (1*1*1) + (5*5*5) + (3*3*3)
Statement of C Program: Enter a number and check it is Armstrong or not:
#include<conio.h>
void main()
{
int a,b,c,d;
clrscr();
printf(" Enter a number");
scanf("%d" ,&a);
d=a;
c=0;
while(a>0)
{
b=a%10;
c=c+(b*b*b);
a=a/10;
}
if(c==d)
{
printf(" Number is Armstrong");
}
else
{
printf(" Number is not Armstrong");
}
getch();
}
Output:
Enter a number
153
Number is Armstrong
Output:
Enter a number
180
Number is not Armstrong
0 Response to "Write a Program to check a number it is Armstrong or not by using while and if Statement"
Post a Comment