Pages

Saturday, 2 February 2019

PROGRAM TO FIND WHETHER THE GIVEN NUMBER IS ARMSTRONG OR NOT

THOSE NUMBERS WHOSE SUM OF ITS DIGITS TO POWER OF NUMBER OF ITS DIGITS IS EQUAL TO THAT NUMBER ARE KNOWN AS ARMSTRONG NUMBER
FOR EXAMPLE: 153
TOTAL DIGITS IN 153 IS 3 
THEREFORE = 1^3 + 5^3 +3^3
                       =    1   +  125  + 27
                       = 153                    


FOR EXAMPLE: 1634
TOTAL DIGITS IN 1634 IS 4
THEREFORE = 1^4  +  6^4  + 3^4  + 4^4
                       =    1   +  1296   + 81   + 64
                       = 1634                   

// prg to illustrate given number is Armstrong or not


#include<stdio.h>
void main()
{
 printf("enter any number:");

 int n,r,arm=0,temp;


 scanf("%d",&n);

 temp=n;

 while(n != 0)

  {

   r = n % 10;

   n = n / 10;

   arm=arm + (r * r * r);

  }

  if( temp == arm )

   printf("%d  is an armstrong  \n",temp);

  else

   printf("%d  is not a armstrong \n",temp);

}  

OUTPUT:

 

No comments:

Post a Comment

Programs in turboc3 : Files

File Handling in C File Handling concept in C language is used for store a data permanently in computer. Using this concept we can store our...