Monday, November 3, 2014

First of all we all should know what is Armstrong number?

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.
Example: 371 is an Armstrong number since 3*3*3 + 7*7*7 + 1*1*1 = 371.


PROGRAM

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
int main(){
    int num,r,sum=0,temp;

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

    temp=num;
    while(num!=0){
         r=num%10;
         num=num/10;
         sum=sum+(r*r*r);
    }
    if(sum==temp)
         printf("%d is an Armstrong number",temp);
    else
         printf("%d is not an Armstrong number",temp);

    return 0;
}

0 comments:

Post a Comment