Armstrong Number Using C program
Armstrong Number:
Armstrong number is the number which is equal to sum of cube of its digits.
Example1:
153 is armstrong number.
Explanation:
153=(1*1*1)+(5*5*5)+(3*3*3)
=(1)+(125)+(27)
=153
Example2:
354 is not armstrong number.
Explanation:
354=(3*3*3)+(5*5*5)+(4*4*4)
=27+125+64
=216
354≠216
C Program:
Output 1:
Output 2:
From the above program,
ü Let's take num=153
ü n=num, n=153
n>0 |
r=n%10 |
sum=sum+(r*r*r) |
n=n/10 |
153>0 |
r=153%10 =3 |
sum=0+(3*3*3) =27 |
n=153/10 =15 |
15>0 |
r=15%10 =5 |
sum=27+(5*5*5) =27+125 =152 |
n=15/10 = 1 |
1>0 |
r=1%10 =1 |
sum=152+(1*1*1) =152+1 =153 |
n=1/10 =0 |
0>0 false |
|
0 Comments