Armstrong number {using loops}

 Using while loop

#include<stdio.h>
#include<conio.h>
void main()
{
    int n,r,c,sum=0,temp;
    printf("enter numbers = ");
    scanf("%d",&n);
    temp=n;
    while(n>0)
    {
        r=n%10;
        c=r*r*r;
        sum=sum+c;
         n=n/10;
    }
    n=temp;
    if(n==sum)
        printf("Armstrong number");
    else
        printf("not a Armstrong number");
    getch();
}

Output

1. enter numbers = 153
Armstrong number
2. enter numbers = 372
 Not a Armstrong number

Comments