Monday 20 January 2014

Filled Under: ,

Write a program to read a number and to test whether it is an Armstrong number or not?

#include<stdio.h>
#include<conio.h>
void main()
{
    int num,temp,rem,sum=0;

    printf("Enter a number:");
    scanf("%d",&num);
    temp=num;

    while(temp!=0)
    {
        rem=temp%10;
        sum=sum+(rem*rem*rem);
        temp=temp/10;
    }

    if(sum==num)
        printf("\n%d is an Armstrong Number.",num);
    else
        printf("\n%d is not an Armstrong Number.",num);

    getch();
}

0 comments:

Post a Comment