Tuesday, 17 December 2013

Armstrong number

/*
Q17.    Write a program to check whether a number is armstrong or not.
*/

#include<stdio.h>

main()
{
    int num,temp,flag=0,sum=0;  
    printf("\nEnter a number=");
    scanf("%d",&num);
    temp=num;
    while(num)
    {
    r=num%10;
        sum=sum+r*r*r;
        num=num/10;
    }          
    if(sum==temp)
        printf("\n%d is an armstrong number",temp);
    else
        printf("\n%d is not an armstrong number",temp);          
}

No comments:

Post a Comment