Code Competitions

Coding competition

Sunday, 12 May 2013

Program to check the number is Armstrong or not?

#include<stdio.h>
#include<conio.h>
void main()
{
    unsigned int a,b,sum=0,c;
    clrscr();
    printf("enter the number");
    scanf("%d",&a);
    c=a;
    while(a>0)
    {
        b=a%10;
        a=a/10;
        sum=sum+(b*b*b);
    }
    if(sum==c)
    {
        printf("number is armstrong");
    }
    else
    {
        printf("number is not armstrong");
    }
    getche();
}

No comments:

Post a Comment