Program to check if number is Armstrong or not
Armstrong number is number in which sum of cube of its all digits is equal to original number itself.e.g: 153.
Here,
13+53+33=1 + 125 + 27 = 153.
So, 153 is an Armstrong number.
Program:
#include<stdio.h>
void main()
{
int n,a,b,c;
c=0;
printf("Enter number of which you want
to test: ");
scanf("%d",&n);
a=n;
while(a!=0)
{
b=a%10;
c=(b*b*b)+c;
a=a/10;
}
if(c!=n)
{
printf("Not Armstrong!!!");
}
else
{
printf("Armstrong!!!");
}
}
Output:
No comments:
Post a Comment