First know about what is ARMSTRONG NUMBER-"If sum of the digits raise to the power number of the digits is equal to given number,then it is ARMSTRONG number".
one digit armstrong number are 1,2,3,4,5,6,7,8,9.
two digit armstrong number are not possible.
three digit armstrong number are 153,370,371,407.
four digit armstrong number are 1634,8208,9474.
#include<stdio.h>
#include<math.h>
int main()
{
int num,temp,d1,d2,d3,sum;
printf("enter any three digit number");
scanf("%3d",&num);
temp=num;
d1=num%10;
num=num/10;
d2=num%10;
num=num/10;
d3=num%10;
num=num/10;
sum=pow(d1,3)+pow(d2,3)+pow(d3,3);
(sum==temp)?printf("armstrong number"):printf("not armstrong number");
return 0;
}
one digit armstrong number are 1,2,3,4,5,6,7,8,9.
two digit armstrong number are not possible.
three digit armstrong number are 153,370,371,407.
four digit armstrong number are 1634,8208,9474.
#include<stdio.h>
#include<math.h>
int main()
{
int num,temp,d1,d2,d3,sum;
printf("enter any three digit number");
scanf("%3d",&num);
temp=num;
d1=num%10;
num=num/10;
d2=num%10;
num=num/10;
d3=num%10;
num=num/10;
sum=pow(d1,3)+pow(d2,3)+pow(d3,3);
(sum==temp)?printf("armstrong number"):printf("not armstrong number");
return 0;
}
No comments:
Post a Comment