TheAlgorithms-C/misc/is_Armstrong.c

25 lines
310 B
C
Raw Normal View History

2016-10-08 14:02:23 +03:00
#include<stdio.h>
int main()
{
int n, sum=0, i, num;
printf("Enter number: ");
scanf("%d",&n);
num=n;
while (n!=0)
{
i=n%10;
sum=sum+(i*i*i);
n=n/10;
}
if (sum==num)
{
2017-11-02 12:26:45 +03:00
printf("%d is an armstrong number!\n", num);
2016-10-08 14:02:23 +03:00
}
else
{
2017-11-02 12:26:45 +03:00
printf("%d is not an armstrong number!\n", num);
2016-10-08 14:02:23 +03:00
}
return 0;
2017-11-02 12:26:45 +03:00
}