Armstrong number example in C

Armstrong number is a number, which is equal to sum of digits raise to the power total number of digits in the number. Some Armstrong numbers are: 0, 1, 2, 3, 153, 370, 407, 1634, 8208 etc.

Examples:

153=1^3+5^3+3^3=1+125+9=153
1634=1^4+6^4+3^4+4^4=1+1296+81+256=1634

Check whether given three digit number is Armstrong number or not:

void main()
{
int n, temp, i, sum=0;
clrscr();
printf(“Enter a value:”);
scanf(“%d”,&n);
for temp=n;temp!=0;)
{
i=temp%10;
sum=sum+(i*i*i);
temp=temp/10;
}
if(n==sum&&n!=0)
printf(“\n%d is Armstrong number number”,n);
else
printf(“\n%d is not Armstrong number number”,n);
getch()
}

Execute the program:

Enter a value: 153
output: 153 is Armstrong number number

Visit for more C Prgramming Tutorials

Related Posts

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools