C Programming Tutorial

Advertisements

Write program to check whether a number is Armstrong or not in c



       #include<stdio.h>
       #include<conio.h>
       void main()
       {
              int num,i,m,sum=0,n;
              clrscr();
              
              printf("Enter any number : "); 
              scanf("%d",&num); 
              
              n = num;
                            
              while(num>0)
              {
                     m = num % 10;                     
                     sum = sum + (m * m * m);                     
                     num =num / 10;
              }
              
              if(sum == n)
                   printf("\nYes! given number is Armstrong number.");
              else
                   printf("\nYes! given number is not Armstrong number.");

              getch();
}

   Output : 

              Enter any number : 371
              Yes! given number is Armstrong number.




Advertisement