Ad Code

Responsive Advertisement

Armstrong Number Using C

 

 Armstrong Number Using C program

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:

Armstrong Number

Output 2:

Armstrong Number output

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

                      doesn't  execute


 Ã¼ after the execution of above table, sum= 153.

 Ã¼  now it checks the condition sum==num(153==153), since the condition is true, it is armstrong number.

 

Post a Comment

0 Comments

Close Menu