Armstrong Number :
The number which the sum of the cube of its digits is equal to that number is known as Armstrong Number.
for example:
number = 153
Total digits in 153 is 3
Now, 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
Program to check whether a number is Armstrong Number
#include<stdio.h>
int main()
{
int num, r, sum =0, temp;
printf("Enter a number \n");
scanf("%d",&num);
temp = num;
while(num>0) {
r = num%10;
sum = sum + ( r * r * r );
num = num / 10;
}
if ( sum = = temp )
printf("%d is a armstrong number \n", num);
else
printf("%d is not a armstrong number \n",num);
return 0 ;
}
No comments:
Post a Comment