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
No comments:
Post a Comment