Tuesday, 10 January 2012

Armstrong Number

 Armstrong Number means the sum of the digit's cube is equal to thae number.
as an example 153=(1*1*1)+(5*5*5)+(3*3*3)

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
    int n,a,b,rem,sum=0,ct=0;
    clrscr();
    printf("Enter the number::\n");
    scanf("%d",&n);
    a=n;
    b=n;
    while(a!=0)
    {
        a=a/10;
        ct++;
    }
    while(b!=0)
    {
        rem=b%10;
        sum=sum+pow(rem,ct);
        b=b/10;
    }
    if(sum==n)
    {
        printf("It is Armstrong number::");
    }
    else
    {
        printf("Its not Armstrong number::");
    }
    getch();
}

No comments:

Post a Comment